signal-desktop/ts/components/conversation/MessageDetail.stories.tsx

269 lines
7 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-08-27 18:10:35 +00:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
import type { PropsData as MessageDataPropsType } from './Message';
import { TextDirection } from './Message';
import type { Props } from './MessageDetail';
import { MessageDetail } from './MessageDetail';
import { SendStatus } from '../../messages/MessageSendState';
import { ReadStatus } from '../../messages/MessageReadStatus';
2021-05-07 22:21:10 +00:00
import { getDefaultConversation } from '../../test-both/helpers/getDefaultConversation';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../util/setupI18n';
2020-08-27 18:10:35 +00:00
import enMessages from '../../../_locales/en/messages.json';
import { getFakeBadge } from '../../test-both/helpers/getFakeBadge';
import { ThemeType } from '../../types/Util';
2020-09-14 19:51:27 +00:00
2020-08-27 18:10:35 +00:00
const i18n = setupI18n('en', enMessages);
const defaultMessage: MessageDataPropsType = {
2021-05-07 22:21:10 +00:00
author: getDefaultConversation({
2021-04-27 19:55:21 +00:00
id: 'some-id',
title: 'Max',
2021-05-07 22:21:10 +00:00
}),
canDeleteForEveryone: true,
2021-05-28 16:15:17 +00:00
conversationColor: 'crimson',
2020-08-27 18:10:35 +00:00
conversationId: 'my-convo',
2022-05-11 20:59:58 +00:00
conversationTitle: 'Conversation Title',
2020-08-27 18:10:35 +00:00
conversationType: 'direct',
direction: 'incoming',
id: 'my-message',
renderingContext: 'storybook',
2022-12-19 22:33:55 +00:00
renderMenu: undefined,
isBlocked: false,
isMessageRequestAccepted: true,
2023-03-20 22:23:53 +00:00
isSelected: false,
isSelectMode: false,
isSpoilerExpanded: {},
2020-08-27 18:10:35 +00:00
previews: [],
readStatus: ReadStatus.Read,
2020-08-27 18:10:35 +00:00
status: 'sent',
text: 'A message from Max',
textDirection: TextDirection.Default,
2020-08-27 18:10:35 +00:00
timestamp: Date.now(),
};
export default {
title: 'Components/Conversation/MessageDetail',
argTypes: {
message: { control: { type: 'text' } },
receivedAt: { control: { type: 'number' } },
sentAt: { control: { type: 'number' } },
},
args: {
contacts: [
{
...getDefaultConversation({
title: 'Just Max',
}),
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Delivered,
},
],
errors: [],
message: defaultMessage,
receivedAt: Date.now(),
sentAt: Date.now(),
2020-08-27 18:10:35 +00:00
getPreferredBadge: () => getFakeBadge(),
i18n,
platform: 'darwin',
interactionMode: 'keyboard',
theme: ThemeType.light,
toggleSafetyNumberModal: action('toggleSafetyNumberModal'),
checkForAccount: action('checkForAccount'),
clearTargetedMessage: action('clearTargetedMessage'),
showLightboxForViewOnceMedia: action('showLightboxForViewOnceMedia'),
doubleCheckMissingQuoteReference: action(
'doubleCheckMissingQuoteReference'
),
kickOffAttachmentDownload: action('kickOffAttachmentDownload'),
markAttachmentAsCorrupted: action('markAttachmentAsCorrupted'),
messageExpanded: action('messageExpanded'),
showConversation: action('showConversation'),
openGiftBadge: action('openGiftBadge'),
renderAudioAttachment: () => <div>AudioAttachment</div>,
saveAttachment: action('saveAttachment'),
showSpoiler: action('showSpoiler'),
retryMessageSend: action('retryMessageSend'),
pushPanelForConversation: action('pushPanelForConversation'),
showContactModal: action('showContactModal'),
showExpiredIncomingTapToViewToast: action(
'showExpiredIncomingTapToViewToast'
),
showExpiredOutgoingTapToViewToast: action(
'showExpiredOutgoingTapToViewToast'
),
showLightbox: action('showLightbox'),
startConversation: action('startConversation'),
viewStory: action('viewStory'),
},
} satisfies Meta<Props>;
export function DeliveredIncoming(args: Props): JSX.Element {
return (
<MessageDetail
{...args}
contacts={[
{
...getDefaultConversation({
color: 'forest',
title: 'Max',
}),
status: undefined,
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
},
]}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-27 18:10:35 +00:00
export function DeliveredOutgoing(args: Props): JSX.Element {
return (
<MessageDetail
{...args}
message={{
...defaultMessage,
direction: 'outgoing',
text: 'A message to Max',
}}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-27 18:10:35 +00:00
export function MessageStatuses(args: Props): JSX.Element {
return (
<MessageDetail
{...args}
contacts={[
{
...getDefaultConversation({
title: 'Max',
}),
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Sent,
},
{
...getDefaultConversation({
title: 'Sally',
}),
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Pending,
},
{
...getDefaultConversation({
title: 'Terry',
}),
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Failed,
},
{
...getDefaultConversation({
title: 'Theo',
}),
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Delivered,
},
{
...getDefaultConversation({
title: 'Nikki',
}),
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Read,
},
]}
message={{
...defaultMessage,
conversationType: 'group',
text: 'A message to you all!',
}}
/>
);
}
2020-08-27 18:10:35 +00:00
export function NotDelivered(args: Props): JSX.Element {
return (
<MessageDetail
{...args}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
receivedAt={undefined as any}
message={{
...defaultMessage,
direction: 'outgoing',
text: 'A message to Max',
}}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-27 18:10:35 +00:00
export function NoContacts(args: Props): JSX.Element {
return (
<MessageDetail
{...args}
contacts={[]}
message={{
...defaultMessage,
direction: 'outgoing',
text: 'Is anybody there?',
}}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-27 18:10:35 +00:00
export function AllErrors(args: Props): JSX.Element {
return (
<MessageDetail
{...args}
errors={[
{
name: 'Another Error',
message: 'Wow, that went bad.',
},
]}
contacts={[
{
...getDefaultConversation({
title: 'Max',
}),
isOutgoingKeyError: true,
isUnidentifiedDelivery: false,
status: SendStatus.Failed,
},
{
...getDefaultConversation({
title: 'Sally',
}),
errors: [
{
name: 'Big Error',
message: 'Stuff happened, in a bad way.',
},
],
isOutgoingKeyError: false,
isUnidentifiedDelivery: true,
status: SendStatus.Failed,
},
{
...getDefaultConversation({
title: 'Terry',
}),
isOutgoingKeyError: true,
isUnidentifiedDelivery: true,
status: SendStatus.Failed,
},
]}
/>
);
2022-11-18 00:45:19 +00:00
}