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';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsType } from './ForwardMessageModal';
|
|
|
|
import { ForwardMessageModal } from './ForwardMessageModal';
|
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';
|
2021-04-27 22:35:35 +00:00
|
|
|
|
2021-12-03 01:05:32 +00:00
|
|
|
const createAttachment = (
|
|
|
|
props: Partial<AttachmentType> = {}
|
|
|
|
): AttachmentType => ({
|
2021-11-15 21:54:33 +00:00
|
|
|
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 || ''),
|
2021-11-15 21:54:33 +00:00
|
|
|
screenshotPath: props.pending === false ? props.screenshotPath : undefined,
|
|
|
|
url: text('attachment url', props.pending === false ? props.url || '' : ''),
|
2021-10-05 22:10:08 +00:00
|
|
|
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 => ({
|
2021-04-27 22:35:35 +00:00
|
|
|
attachments: overrideProps.attachments,
|
|
|
|
candidateConversations,
|
|
|
|
doForwardMessage: action('doForwardMessage'),
|
2021-11-17 18:38:52 +00:00
|
|
|
getPreferredBadge: () => undefined,
|
2021-04-27 22:35:35 +00:00
|
|
|
i18n,
|
2022-04-11 20:57:44 +00:00
|
|
|
hasContact: Boolean(overrideProps.hasContact),
|
2021-04-27 22:35:35 +00:00
|
|
|
isSticker: Boolean(overrideProps.isSticker),
|
|
|
|
linkPreview: overrideProps.linkPreview,
|
|
|
|
messageBody: text('messageBody', overrideProps.messageBody || ''),
|
|
|
|
onClose: action('onClose'),
|
|
|
|
onEditorStateChange: action('onEditorStateChange'),
|
|
|
|
removeLinkPreview: action('removeLinkPreview'),
|
2022-10-04 23:17:15 +00:00
|
|
|
RenderCompositionTextArea: props => (
|
|
|
|
<CompositionTextArea
|
|
|
|
{...props}
|
|
|
|
i18n={i18n}
|
|
|
|
onPickEmoji={action('onPickEmoji')}
|
|
|
|
skinTone={0}
|
|
|
|
onSetSkinTone={action('onSetSkinTone')}
|
|
|
|
onTextTooLong={action('onTextTooLong')}
|
|
|
|
getPreferredBadge={() => undefined}
|
|
|
|
/>
|
|
|
|
),
|
2021-11-02 23:01:13 +00:00
|
|
|
theme: React.useContext(StorybookThemeContext),
|
2022-04-05 00:38:22 +00:00
|
|
|
regionCode: 'US',
|
2021-04-27 22:35:35 +00:00
|
|
|
});
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function Modal(): JSX.Element {
|
2021-11-02 23:01:13 +00:00
|
|
|
return <ForwardMessageModal {...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 {
|
2021-11-02 23:01:13 +00:00
|
|
|
return <ForwardMessageModal {...useProps({ 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 {
|
2021-11-02 23:01:13 +00:00
|
|
|
return <ForwardMessageModal {...useProps({ 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 {
|
2022-04-11 20:57:44 +00:00
|
|
|
return <ForwardMessageModal {...useProps({ 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-04-11 20:57:44 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function LinkPreview(): JSX.Element {
|
2021-04-27 22:35:35 +00:00
|
|
|
return (
|
|
|
|
<ForwardMessageModal
|
2021-11-02 23:01:13 +00:00
|
|
|
{...useProps({
|
2021-04-27 22:35:35 +00:00
|
|
|
linkPreview: {
|
|
|
|
description: LONG_DESCRIPTION,
|
|
|
|
date: Date.now(),
|
|
|
|
domain: 'https://www.signal.org',
|
|
|
|
url: 'signal.org',
|
2021-12-03 01:05:32 +00:00
|
|
|
image: createAttachment({
|
2021-04-27 22:35:35 +00:00
|
|
|
url: '/fixtures/kitten-4-112-112.jpg',
|
|
|
|
contentType: IMAGE_JPEG,
|
|
|
|
}),
|
|
|
|
isStickerPack: false,
|
|
|
|
title: LONG_TITLE,
|
|
|
|
},
|
|
|
|
messageBody: 'signal.org',
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
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 (
|
|
|
|
<ForwardMessageModal
|
2021-11-02 23:01:13 +00:00
|
|
|
{...useProps({
|
2021-04-27 22:35:35 +00:00
|
|
|
attachments: [
|
2021-12-03 01:05:32 +00:00
|
|
|
createAttachment({
|
2021-11-15 21:54:33 +00:00
|
|
|
pending: true,
|
|
|
|
}),
|
2021-12-03 01:05:32 +00:00
|
|
|
createAttachment({
|
2021-04-27 22:35:35 +00:00
|
|
|
contentType: IMAGE_JPEG,
|
|
|
|
fileName: 'tina-rolf-269345-unsplash.jpg',
|
|
|
|
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
|
|
|
|
}),
|
2021-12-03 01:05:32 +00:00
|
|
|
createAttachment({
|
2021-04-27 22:35:35 +00:00
|
|
|
contentType: VIDEO_MP4,
|
|
|
|
fileName: 'pixabay-Soap-Bubble-7141.mp4',
|
|
|
|
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
|
2021-11-15 21:54:33 +00:00
|
|
|
screenshotPath: '/fixtures/kitten-4-112-112.jpg',
|
2021-04-27 22:35:35 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
messageBody: 'cats',
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
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 (
|
|
|
|
<ForwardMessageModal
|
|
|
|
{...useProps()}
|
|
|
|
candidateConversations={[
|
|
|
|
getDefaultConversation({
|
|
|
|
announcementsOnly: true,
|
|
|
|
areWeAdmin: false,
|
|
|
|
}),
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
|
|
|
AnnouncementOnlyGroupsNonAdmin.story = {
|
|
|
|
name: 'announcement only groups non-admin',
|
|
|
|
};
|