2022-03-04 21:14:52 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-07-25 18:55:44 +00:00
|
|
|
import type { Meta, Story } from '@storybook/react';
|
2022-03-04 21:14:52 +00:00
|
|
|
import React from 'react';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { v4 as generateUuid } from 'uuid';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-10-11 17:59:02 +00:00
|
|
|
import { useArgs } from '@storybook/addons';
|
2022-03-04 21:14:52 +00:00
|
|
|
import type { PropsType } from './StoryViewsNRepliesModal';
|
|
|
|
import * as durations from '../util/durations';
|
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
2022-07-01 00:52:03 +00:00
|
|
|
import { SendStatus } from '../messages/MessageSendState';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { StoryViewsNRepliesModal } from './StoryViewsNRepliesModal';
|
|
|
|
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
|
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2022-10-11 17:59:02 +00:00
|
|
|
import { StoryViewTargetType } from '../types/Stories';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/StoryViewsNRepliesModal',
|
2022-07-25 18:55:44 +00:00
|
|
|
component: StoryViewsNRepliesModal,
|
|
|
|
argTypes: {
|
|
|
|
authorTitle: {
|
|
|
|
defaultValue: getDefaultConversation().title,
|
|
|
|
},
|
|
|
|
canReply: {
|
|
|
|
defaultValue: true,
|
|
|
|
},
|
|
|
|
getPreferredBadge: { action: true },
|
2022-10-25 22:18:42 +00:00
|
|
|
hasViewReceiptSetting: {
|
|
|
|
control: 'boolean',
|
2022-08-31 16:11:14 +00:00
|
|
|
defaultValue: true,
|
|
|
|
},
|
2022-09-21 19:19:16 +00:00
|
|
|
hasViewsCapability: {
|
2022-10-25 22:18:42 +00:00
|
|
|
control: 'boolean',
|
2022-09-21 19:19:16 +00:00
|
|
|
defaultValue: false,
|
|
|
|
},
|
2022-07-25 18:55:44 +00:00
|
|
|
i18n: {
|
|
|
|
defaultValue: i18n,
|
|
|
|
},
|
2023-04-03 20:16:27 +00:00
|
|
|
platform: {
|
|
|
|
defaultValue: 'darwin',
|
|
|
|
},
|
2022-07-25 18:55:44 +00:00
|
|
|
onClose: { action: true },
|
|
|
|
onSetSkinTone: { action: true },
|
|
|
|
onReact: { action: true },
|
|
|
|
onReply: { action: true },
|
|
|
|
onTextTooLong: { action: true },
|
|
|
|
onUseEmoji: { action: true },
|
|
|
|
preferredReactionEmoji: {
|
|
|
|
defaultValue: ['❤️', '👍', '👎', '😂', '😮', '😢'],
|
|
|
|
},
|
|
|
|
renderEmojiPicker: { action: true },
|
|
|
|
replies: {
|
|
|
|
defaultValue: [],
|
|
|
|
},
|
|
|
|
views: {
|
|
|
|
defaultValue: [],
|
|
|
|
},
|
2022-10-11 17:59:02 +00:00
|
|
|
viewTarget: {
|
|
|
|
defaultValue: StoryViewTargetType.Views,
|
|
|
|
},
|
|
|
|
onChangeViewTarget: {
|
|
|
|
action: true,
|
|
|
|
},
|
2022-07-25 18:55:44 +00:00
|
|
|
},
|
|
|
|
} as Meta;
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
function getViewsAndReplies() {
|
|
|
|
const p1 = getDefaultConversation();
|
|
|
|
const p2 = getDefaultConversation();
|
|
|
|
const p3 = getDefaultConversation();
|
|
|
|
const p4 = getDefaultConversation();
|
|
|
|
const p5 = getDefaultConversation();
|
2022-08-05 01:29:44 +00:00
|
|
|
const p6 = getDefaultConversation({
|
|
|
|
isMe: true,
|
|
|
|
});
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
const views = [
|
|
|
|
{
|
2022-07-01 00:52:03 +00:00
|
|
|
recipient: p1,
|
|
|
|
status: SendStatus.Viewed,
|
|
|
|
updatedAt: Date.now() - 20 * durations.MINUTE,
|
2022-03-04 21:14:52 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-01 00:52:03 +00:00
|
|
|
recipient: p2,
|
|
|
|
status: SendStatus.Viewed,
|
|
|
|
updatedAt: Date.now() - 25 * durations.MINUTE,
|
2022-03-04 21:14:52 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-01 00:52:03 +00:00
|
|
|
recipient: p3,
|
|
|
|
status: SendStatus.Viewed,
|
|
|
|
updatedAt: Date.now() - 15 * durations.MINUTE,
|
2022-03-04 21:14:52 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-01 00:52:03 +00:00
|
|
|
recipient: p4,
|
|
|
|
status: SendStatus.Viewed,
|
|
|
|
updatedAt: Date.now() - 5 * durations.MINUTE,
|
2022-03-04 21:14:52 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-01 00:52:03 +00:00
|
|
|
recipient: p5,
|
|
|
|
status: SendStatus.Viewed,
|
|
|
|
updatedAt: Date.now() - 30 * durations.MINUTE,
|
2022-03-04 21:14:52 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const replies = [
|
|
|
|
{
|
2022-08-05 01:29:44 +00:00
|
|
|
author: p2,
|
2022-03-04 21:14:52 +00:00
|
|
|
body: 'So cute ❤️',
|
2022-08-05 01:29:44 +00:00
|
|
|
conversationId: p2.id,
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-03-04 21:14:52 +00:00
|
|
|
timestamp: Date.now() - 24 * durations.MINUTE,
|
|
|
|
},
|
|
|
|
{
|
2022-08-05 01:29:44 +00:00
|
|
|
author: p3,
|
2022-03-04 21:14:52 +00:00
|
|
|
body: "That's awesome",
|
2022-08-05 01:29:44 +00:00
|
|
|
conversationId: p3.id,
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-03-04 21:14:52 +00:00
|
|
|
timestamp: Date.now() - 13 * durations.MINUTE,
|
|
|
|
},
|
|
|
|
{
|
2022-08-05 01:29:44 +00:00
|
|
|
author: p3,
|
|
|
|
body: 'Very awesome',
|
|
|
|
conversationId: p3.id,
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-08-05 01:29:44 +00:00
|
|
|
timestamp: Date.now() - 13 * durations.MINUTE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
author: p3,
|
|
|
|
body: 'Did I mention how awesome this is?',
|
|
|
|
conversationId: p3.id,
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-08-05 01:29:44 +00:00
|
|
|
timestamp: Date.now() - 12 * durations.MINUTE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
author: p4,
|
|
|
|
conversationId: p4.id,
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-03-04 21:14:52 +00:00
|
|
|
reactionEmoji: '❤️',
|
|
|
|
timestamp: Date.now() - 5 * durations.MINUTE,
|
|
|
|
},
|
2022-08-05 01:29:44 +00:00
|
|
|
{
|
|
|
|
author: p6,
|
|
|
|
body: 'Thanks everyone!',
|
|
|
|
conversationId: p6.id,
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-08-05 01:29:44 +00:00
|
|
|
sendStateByConversationId: {
|
|
|
|
[p1.id]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
timestamp: Date.now(),
|
|
|
|
},
|
2022-03-04 21:14:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
return {
|
|
|
|
views,
|
|
|
|
replies,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
// eslint-disable-next-line react/function-component-definition
|
2022-10-11 17:59:02 +00:00
|
|
|
const Template: Story<PropsType> = args => {
|
|
|
|
const [, updateArgs] = useArgs();
|
|
|
|
|
|
|
|
function onChangeViewTarget(viewTarget: StoryViewTargetType) {
|
|
|
|
args.onChangeViewTarget(viewTarget);
|
|
|
|
updateArgs({ viewTarget });
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StoryViewsNRepliesModal
|
|
|
|
{...args}
|
|
|
|
onChangeViewTarget={onChangeViewTarget}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-07-25 18:55:44 +00:00
|
|
|
export const CanReply = Template.bind({});
|
|
|
|
CanReply.args = {};
|
|
|
|
CanReply.storyName = 'Can reply';
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-07-25 18:55:44 +00:00
|
|
|
export const ViewsOnly = Template.bind({});
|
|
|
|
ViewsOnly.args = {
|
2022-09-21 19:19:16 +00:00
|
|
|
canReply: false,
|
|
|
|
hasViewsCapability: true,
|
2022-07-25 18:55:44 +00:00
|
|
|
views: getViewsAndReplies().views,
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
2022-07-25 18:55:44 +00:00
|
|
|
ViewsOnly.storyName = 'Views only';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-09-21 19:19:16 +00:00
|
|
|
export const NoViews = Template.bind({});
|
|
|
|
NoViews.args = {
|
|
|
|
canReply: false,
|
|
|
|
hasViewsCapability: true,
|
|
|
|
views: [],
|
|
|
|
};
|
|
|
|
NoViews.storyName = 'No views';
|
|
|
|
|
2022-07-25 18:55:44 +00:00
|
|
|
export const InAGroupNoReplies = Template.bind({});
|
|
|
|
InAGroupNoReplies.args = {
|
2022-10-14 14:03:37 +00:00
|
|
|
group: {},
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
2022-07-25 18:55:44 +00:00
|
|
|
InAGroupNoReplies.storyName = 'In a group (no replies)';
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-07-25 18:55:44 +00:00
|
|
|
export const InAGroup = Template.bind({});
|
|
|
|
{
|
2022-03-04 21:14:52 +00:00
|
|
|
const { views, replies } = getViewsAndReplies();
|
2022-07-25 18:55:44 +00:00
|
|
|
InAGroup.args = {
|
2022-09-21 19:19:16 +00:00
|
|
|
hasViewsCapability: true,
|
2022-10-14 14:03:37 +00:00
|
|
|
group: {},
|
2022-07-25 18:55:44 +00:00
|
|
|
replies,
|
|
|
|
views,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
InAGroup.storyName = 'In a group';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-07-25 18:55:44 +00:00
|
|
|
export const CantReply = Template.bind({});
|
|
|
|
CantReply.args = {
|
|
|
|
canReply: false,
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
|
|
|
|
2022-07-25 18:55:44 +00:00
|
|
|
export const InAGroupCantReply = Template.bind({});
|
|
|
|
{
|
|
|
|
const { views, replies } = getViewsAndReplies();
|
|
|
|
InAGroupCantReply.args = {
|
|
|
|
canReply: false,
|
2022-10-14 14:03:37 +00:00
|
|
|
group: {},
|
2022-07-25 18:55:44 +00:00
|
|
|
replies,
|
|
|
|
views,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
InAGroupCantReply.storyName = "In a group (can't reply)";
|
2022-08-31 16:11:14 +00:00
|
|
|
|
|
|
|
export const ReadReceiptsTurnedOff = Template.bind({});
|
|
|
|
ReadReceiptsTurnedOff.args = {
|
|
|
|
canReply: false,
|
2022-10-25 22:18:42 +00:00
|
|
|
hasViewReceiptSetting: false,
|
2022-09-21 19:19:16 +00:00
|
|
|
hasViewsCapability: true,
|
2022-08-31 16:11:14 +00:00
|
|
|
views: getViewsAndReplies().views,
|
|
|
|
};
|
|
|
|
ReadReceiptsTurnedOff.storyName = 'Read receipts turned off';
|
|
|
|
|
2022-10-14 14:03:37 +00:00
|
|
|
export const InAGroupButLeft = Template.bind({});
|
|
|
|
{
|
|
|
|
const { replies } = getViewsAndReplies();
|
|
|
|
InAGroupButLeft.args = {
|
|
|
|
group: { left: true },
|
|
|
|
replies,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
InAGroupButLeft.storyName = 'In a group (but left)';
|
|
|
|
|
2022-08-31 16:11:14 +00:00
|
|
|
export const GroupReadReceiptsOff = Template.bind({});
|
|
|
|
{
|
|
|
|
const { views, replies } = getViewsAndReplies();
|
|
|
|
GroupReadReceiptsOff.args = {
|
2022-10-25 22:18:42 +00:00
|
|
|
hasViewReceiptSetting: false,
|
2022-09-21 19:19:16 +00:00
|
|
|
hasViewsCapability: true,
|
2022-10-14 14:03:37 +00:00
|
|
|
group: {},
|
2022-08-31 16:11:14 +00:00
|
|
|
replies,
|
|
|
|
views,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
GroupReadReceiptsOff.storyName = 'Read receipts turned off (group)';
|