signal-desktop/ts/components/StoryViewsNRepliesModal.stories.tsx

154 lines
3.6 KiB
TypeScript
Raw Normal View History

2022-03-04 21:14:52 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { action } from '@storybook/addon-actions';
import type { PropsType } from './StoryViewsNRepliesModal';
import * as durations from '../util/durations';
import enMessages from '../../_locales/en/messages.json';
import { IMAGE_JPEG } from '../types/MIME';
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 { fakeAttachment } from '../test-both/helpers/fakeAttachment';
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
import { setupI18n } from '../util/setupI18n';
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/StoryViewsNRepliesModal',
};
2022-03-04 21:14:52 +00:00
function getDefaultProps(): PropsType {
return {
authorTitle: getDefaultConversation().title,
getPreferredBadge: () => undefined,
i18n,
isMyStory: false,
onClose: action('onClose'),
onSetSkinTone: action('onSetSkinTone'),
onReact: action('onReact'),
onReply: action('onReply'),
onTextTooLong: action('onTextTooLong'),
onUseEmoji: action('onUseEmoji'),
preferredReactionEmoji: ['❤️', '👍', '👎', '😂', '😮', '😢'],
renderEmojiPicker: () => <div />,
replies: [],
storyPreviewAttachment: fakeAttachment({
thumbnail: {
contentType: IMAGE_JPEG,
height: 64,
objectUrl: '/fixtures/nathan-anderson-316188-unsplash.jpg',
path: '',
width: 40,
},
}),
views: [],
};
}
function getViewsAndReplies() {
const p1 = getDefaultConversation();
const p2 = getDefaultConversation();
const p3 = getDefaultConversation();
const p4 = getDefaultConversation();
const p5 = getDefaultConversation();
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 = [
{
...p2,
body: 'So cute ❤️',
timestamp: Date.now() - 24 * durations.MINUTE,
},
{
...p3,
body: "That's awesome",
timestamp: Date.now() - 13 * durations.MINUTE,
},
{
...p4,
reactionEmoji: '❤️',
timestamp: Date.now() - 5 * durations.MINUTE,
},
];
return {
views,
replies,
};
}
2022-06-07 00:48:02 +00:00
export const CanReply = (): JSX.Element => (
2022-03-04 21:14:52 +00:00
<StoryViewsNRepliesModal {...getDefaultProps()} />
2022-06-07 00:48:02 +00:00
);
2022-03-04 21:14:52 +00:00
2022-06-07 00:48:02 +00:00
CanReply.story = {
name: 'Can reply',
};
export const ViewsOnly = (): JSX.Element => (
2022-03-04 21:14:52 +00:00
<StoryViewsNRepliesModal
{...getDefaultProps()}
isMyStory
views={getViewsAndReplies().views}
/>
2022-06-07 00:48:02 +00:00
);
ViewsOnly.story = {
name: 'Views only',
};
2022-03-04 21:14:52 +00:00
2022-06-07 00:48:02 +00:00
export const InAGroupNoReplies = (): JSX.Element => (
2022-04-23 03:16:13 +00:00
<StoryViewsNRepliesModal {...getDefaultProps()} isGroupStory />
2022-06-07 00:48:02 +00:00
);
2022-04-23 03:16:13 +00:00
2022-06-07 00:48:02 +00:00
InAGroupNoReplies.story = {
name: 'In a group (no replies)',
};
export const InAGroup = (): JSX.Element => {
2022-03-04 21:14:52 +00:00
const { views, replies } = getViewsAndReplies();
return (
<StoryViewsNRepliesModal
{...getDefaultProps()}
2022-04-23 03:16:13 +00:00
isGroupStory
2022-03-04 21:14:52 +00:00
replies={replies}
views={views}
/>
);
2022-06-07 00:48:02 +00:00
};
InAGroup.story = {
name: 'In a group',
};