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

262 lines
7.1 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 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 { number } from '@storybook/addon-knobs';
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);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/MessageDetail',
};
2020-08-27 18:10:35 +00:00
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
}),
canReact: true,
2020-08-27 18:10:35 +00:00
canReply: true,
canRetry: true,
canRetryDeleteForEveryone: true,
canDeleteForEveryone: true,
canDownload: 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',
isBlocked: false,
isMessageRequestAccepted: true,
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(),
};
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
contacts: overrideProps.contacts || [
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Just Max',
}),
2020-08-27 18:10:35 +00:00
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Delivered,
2020-08-27 18:10:35 +00:00
},
],
errors: overrideProps.errors || [],
message: overrideProps.message || defaultMessage,
receivedAt: number('receivedAt', overrideProps.receivedAt || Date.now()),
sentAt: number('sentAt', overrideProps.sentAt || Date.now()),
getPreferredBadge: () => getFakeBadge(),
i18n,
interactionMode: 'keyboard',
theme: ThemeType.light,
showSafetyNumber: action('showSafetyNumber'),
checkForAccount: action('checkForAccount'),
clearSelectedMessage: action('clearSelectedMessage'),
displayTapToViewMessage: action('displayTapToViewMessage'),
doubleCheckMissingQuoteReference: action('doubleCheckMissingQuoteReference'),
kickOffAttachmentDownload: action('kickOffAttachmentDownload'),
markAttachmentAsCorrupted: action('markAttachmentAsCorrupted'),
markViewed: action('markViewed'),
openConversation: action('openConversation'),
2022-05-11 20:59:58 +00:00
openGiftBadge: action('openGiftBadge'),
openLink: action('openLink'),
reactToMessage: action('reactToMessage'),
renderAudioAttachment: () => <div>*AudioAttachment*</div>,
renderEmojiPicker: () => <div />,
renderReactionPicker: () => <div />,
replyToMessage: action('replyToMessage'),
retrySend: action('retrySend'),
retryDeleteForEveryone: action('retryDeleteForEveryone'),
showContactDetail: action('showContactDetail'),
showContactModal: action('showContactModal'),
showExpiredIncomingTapToViewToast: action(
'showExpiredIncomingTapToViewToast'
),
showExpiredOutgoingTapToViewToast: action(
'showExpiredOutgoingTapToViewToast'
),
showForwardMessageModal: action('showForwardMessageModal'),
showVisualAttachment: action('showVisualAttachment'),
startConversation: action('startConversation'),
2022-07-06 19:06:20 +00:00
viewStory: action('viewStory'),
2020-08-27 18:10:35 +00:00
});
2022-06-07 00:48:02 +00:00
export const DeliveredIncoming = (): JSX.Element => {
const props = createProps({
contacts: [
{
...getDefaultConversation({
color: 'forest',
title: 'Max',
}),
status: undefined,
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
},
],
});
2020-08-27 18:10:35 +00:00
return <MessageDetail {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-27 18:10:35 +00:00
2022-06-07 00:48:02 +00:00
export const DeliveredOutgoing = (): JSX.Element => {
2020-08-27 18:10:35 +00:00
const props = createProps({
message: {
...defaultMessage,
direction: 'outgoing',
text: 'A message to Max',
},
});
return <MessageDetail {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-27 18:10:35 +00:00
2022-06-07 00:48:02 +00:00
export const MessageStatuses = (): JSX.Element => {
2020-08-27 18:10:35 +00:00
const props = createProps({
contacts: [
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Max',
}),
2020-08-27 18:10:35 +00:00
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Sent,
2020-08-27 18:10:35 +00:00
},
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Sally',
}),
2020-08-27 18:10:35 +00:00
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Pending,
2020-08-27 18:10:35 +00:00
},
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Terry',
}),
2020-08-27 18:10:35 +00:00
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Failed,
2020-08-27 18:10:35 +00:00
},
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Theo',
}),
2020-08-27 18:10:35 +00:00
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Delivered,
2020-08-27 18:10:35 +00:00
},
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Nikki',
}),
2020-08-27 18:10:35 +00:00
isOutgoingKeyError: false,
isUnidentifiedDelivery: false,
status: SendStatus.Read,
2020-08-27 18:10:35 +00:00
},
],
message: {
...defaultMessage,
conversationType: 'group',
text: 'A message to you all!',
},
});
return <MessageDetail {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-27 18:10:35 +00:00
2022-06-07 00:48:02 +00:00
export const NotDelivered = (): JSX.Element => {
2020-08-27 18:10:35 +00:00
const props = createProps({
message: {
...defaultMessage,
direction: 'outgoing',
text: 'A message to Max',
},
});
2020-09-14 19:51:27 +00:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2020-08-27 18:10:35 +00:00
props.receivedAt = undefined as any;
return <MessageDetail {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-27 18:10:35 +00:00
2022-06-07 00:48:02 +00:00
export const NoContacts = (): JSX.Element => {
2020-08-27 18:10:35 +00:00
const props = createProps({
contacts: [],
message: {
...defaultMessage,
direction: 'outgoing',
text: 'Is anybody there?',
},
});
return <MessageDetail {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-27 18:10:35 +00:00
2022-06-07 00:48:02 +00:00
export const AllErrors = (): JSX.Element => {
2020-08-27 18:10:35 +00:00
const props = createProps({
errors: [
{
name: 'Another Error',
message: 'Wow, that went bad.',
},
],
message: {
...defaultMessage,
},
contacts: [
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Max',
}),
2020-08-27 18:10:35 +00:00
isOutgoingKeyError: true,
isUnidentifiedDelivery: false,
status: SendStatus.Failed,
2020-08-27 18:10:35 +00:00
},
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Sally',
}),
2020-08-27 18:10:35 +00:00
errors: [
{
name: 'Big Error',
message: 'Stuff happened, in a bad way.',
},
],
isOutgoingKeyError: false,
isUnidentifiedDelivery: true,
status: SendStatus.Failed,
2020-08-27 18:10:35 +00:00
},
{
2021-05-07 22:21:10 +00:00
...getDefaultConversation({
title: 'Terry',
}),
2020-08-27 18:10:35 +00:00
isOutgoingKeyError: true,
isUnidentifiedDelivery: true,
status: SendStatus.Failed,
2020-08-27 18:10:35 +00:00
},
],
});
return <MessageDetail {...props} />;
2022-06-07 00:48:02 +00:00
};