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

220 lines
5.9 KiB
TypeScript
Raw Normal View History

2021-04-27 22:35:35 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import { text } from '@storybook/addon-knobs';
import enMessages from '../../_locales/en/messages.json';
2021-12-03 01:05:32 +00:00
import type { AttachmentType } from '../types/Attachment';
2023-03-20 22:23:53 +00:00
import type { PropsType } from './ForwardMessagesModal';
import { ForwardMessagesModal } from './ForwardMessagesModal';
2021-08-09 20:06:21 +00:00
import { IMAGE_JPEG, VIDEO_MP4, stringToMIMEType } from '../types/MIME';
2021-04-27 22:35:35 +00:00
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2021-11-02 23:01:13 +00:00
import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext';
2022-10-04 23:17:15 +00:00
import { CompositionTextArea } from './CompositionTextArea';
2023-03-20 22:23:53 +00:00
import type { MessageForwardDraft } from '../util/maybeForwardMessages';
2021-04-27 22:35:35 +00:00
2021-12-03 01:05:32 +00:00
const createAttachment = (
props: Partial<AttachmentType> = {}
): AttachmentType => ({
pending: false,
path: 'fileName.jpg',
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType(
text('attachment contentType', props.contentType || '')
),
2021-04-27 22:35:35 +00:00
fileName: text('attachment fileName', props.fileName || ''),
screenshotPath: props.pending === false ? props.screenshotPath : undefined,
url: text('attachment url', props.pending === false ? props.url || '' : ''),
size: 3433,
2021-04-27 22:35:35 +00:00
});
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/ForwardMessageModal',
};
2021-04-27 22:35:35 +00:00
const i18n = setupI18n('en', enMessages);
const LONG_TITLE =
"This is a super-sweet site. And it's got some really amazing content in store for you if you just click that link. Can you click that link for me?";
const LONG_DESCRIPTION =
"You're gonna love this description. Not only does it have a lot of characters, but it will also be truncated in the UI. How cool is that??";
const candidateConversations = Array.from(Array(100), () =>
getDefaultConversation()
);
2021-11-02 23:01:13 +00:00
const useProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
2023-03-20 22:23:53 +00:00
drafts: overrideProps.drafts ?? [],
2021-04-27 22:35:35 +00:00
candidateConversations,
2023-03-20 22:23:53 +00:00
doForwardMessages: action('doForwardMessages'),
2021-11-17 18:38:52 +00:00
getPreferredBadge: () => undefined,
2021-04-27 22:35:35 +00:00
i18n,
2023-03-20 22:23:53 +00:00
linkPreviewForSource: () => undefined,
2021-04-27 22:35:35 +00:00
onClose: action('onClose'),
2023-03-20 22:23:53 +00:00
onChange: action('onChange'),
2021-04-27 22:35:35 +00:00
removeLinkPreview: action('removeLinkPreview'),
2022-10-04 23:17:15 +00:00
RenderCompositionTextArea: props => (
<CompositionTextArea
{...props}
getPreferredBadge={() => undefined}
2022-10-04 23:17:15 +00:00
i18n={i18n}
isFormattingEnabled
isFormattingFlagEnabled
isFormattingSpoilersFlagEnabled
2022-10-04 23:17:15 +00:00
onPickEmoji={action('onPickEmoji')}
onSetSkinTone={action('onSetSkinTone')}
onTextTooLong={action('onTextTooLong')}
platform="darwin"
skinTone={0}
2022-10-04 23:17:15 +00:00
/>
),
2023-03-20 22:23:53 +00:00
showToast: action('showToast'),
2021-11-02 23:01:13 +00:00
theme: React.useContext(StorybookThemeContext),
regionCode: 'US',
2021-04-27 22:35:35 +00:00
});
2023-03-20 22:23:53 +00:00
function getMessageForwardDraft(
overrideProps: Partial<MessageForwardDraft>
): MessageForwardDraft {
return {
attachments: overrideProps.attachments,
hasContact: Boolean(overrideProps.hasContact),
isSticker: Boolean(overrideProps.isSticker),
messageBody: text('messageBody', overrideProps.messageBody || ''),
originalMessageId: '123',
previews: overrideProps.previews ?? [],
};
}
2022-11-18 00:45:19 +00:00
export function Modal(): JSX.Element {
2023-03-20 22:23:53 +00:00
return <ForwardMessagesModal {...useProps()} />;
2022-11-18 00:45:19 +00:00
}
2021-04-27 22:35:35 +00:00
2022-11-18 00:45:19 +00:00
export function WithText(): JSX.Element {
2023-03-20 22:23:53 +00:00
return (
<ForwardMessagesModal
{...useProps({
drafts: [getMessageForwardDraft({ messageBody: 'sup' })],
})}
/>
);
2022-11-18 00:45:19 +00:00
}
2021-04-27 22:35:35 +00:00
2022-06-07 00:48:02 +00:00
WithText.story = {
name: 'with text',
};
2022-11-18 00:45:19 +00:00
export function ASticker(): JSX.Element {
2023-03-20 22:23:53 +00:00
return (
<ForwardMessagesModal
{...useProps({
drafts: [getMessageForwardDraft({ isSticker: true })],
})}
/>
);
2022-11-18 00:45:19 +00:00
}
2021-04-27 22:35:35 +00:00
2022-06-07 00:48:02 +00:00
ASticker.story = {
name: 'a sticker',
};
2022-11-18 00:45:19 +00:00
export function WithAContact(): JSX.Element {
2023-03-20 22:23:53 +00:00
return (
<ForwardMessagesModal
{...useProps({
drafts: [getMessageForwardDraft({ hasContact: true })],
})}
/>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
WithAContact.story = {
name: 'with a contact',
};
2022-11-18 00:45:19 +00:00
export function LinkPreview(): JSX.Element {
2021-04-27 22:35:35 +00:00
return (
2023-03-20 22:23:53 +00:00
<ForwardMessagesModal
2021-11-02 23:01:13 +00:00
{...useProps({
2023-03-20 22:23:53 +00:00
drafts: [
getMessageForwardDraft({
messageBody: 'signal.org',
previews: [
{
description: LONG_DESCRIPTION,
date: Date.now(),
domain: 'https://www.signal.org',
url: 'signal.org',
image: createAttachment({
url: '/fixtures/kitten-4-112-112.jpg',
contentType: IMAGE_JPEG,
}),
isStickerPack: false,
title: LONG_TITLE,
},
],
2021-04-27 22:35:35 +00:00
}),
2023-03-20 22:23:53 +00:00
],
2021-04-27 22:35:35 +00:00
})}
/>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
LinkPreview.story = {
name: 'link preview',
};
2021-04-27 22:35:35 +00:00
2022-11-18 00:45:19 +00:00
export function MediaAttachments(): JSX.Element {
2021-04-27 22:35:35 +00:00
return (
2023-03-20 22:23:53 +00:00
<ForwardMessagesModal
2021-11-02 23:01:13 +00:00
{...useProps({
2023-03-20 22:23:53 +00:00
drafts: [
getMessageForwardDraft({
messageBody: 'cats',
attachments: [
createAttachment({
pending: true,
}),
createAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
}),
createAttachment({
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
screenshotPath: '/fixtures/kitten-4-112-112.jpg',
}),
],
2021-04-27 22:35:35 +00:00
}),
],
})}
/>
);
2022-11-18 00:45:19 +00:00
}
2021-07-20 20:18:35 +00:00
2022-06-07 00:48:02 +00:00
MediaAttachments.story = {
name: 'media attachments',
};
2022-11-18 00:45:19 +00:00
export function AnnouncementOnlyGroupsNonAdmin(): JSX.Element {
return (
2023-03-20 22:23:53 +00:00
<ForwardMessagesModal
2022-11-18 00:45:19 +00:00
{...useProps()}
candidateConversations={[
getDefaultConversation({
announcementsOnly: true,
areWeAdmin: false,
}),
]}
/>
);
}
2022-06-07 00:48:02 +00:00
AnnouncementOnlyGroupsNonAdmin.story = {
name: 'announcement only groups non-admin',
};