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

471 lines
12 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-21 16:09:39 +00:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import { storiesOf } from '@storybook/react';
import { LeftPane, LeftPaneMode, PropsType } from './LeftPane';
import { PropsData as ConversationListItemPropsType } from './conversationList/ConversationListItem';
import { MessageSearchResult } from './conversationList/MessageSearchResult';
2020-08-21 16:09:39 +00:00
import { setup as setupI18n } from '../../js/modules/i18n';
import enMessages from '../../_locales/en/messages.json';
2020-09-12 00:46:52 +00:00
2020-08-21 16:09:39 +00:00
const i18n = setupI18n('en', enMessages);
const story = storiesOf('Components/LeftPane', module);
const defaultConversations: Array<ConversationListItemPropsType> = [
2020-08-21 16:09:39 +00:00
{
id: 'fred-convo',
isSelected: false,
lastUpdated: Date.now(),
markedUnread: false,
2020-08-21 16:09:39 +00:00
title: 'Fred Willard',
type: 'direct',
},
{
id: 'marc-convo',
isSelected: true,
lastUpdated: Date.now(),
markedUnread: false,
2020-08-21 16:09:39 +00:00
title: 'Marc Barraca',
type: 'direct',
},
];
const defaultGroups: Array<ConversationListItemPropsType> = [
{
id: 'biking-group',
isSelected: false,
lastUpdated: Date.now(),
markedUnread: false,
title: 'Mtn Biking Arizona 🚵☀️⛰',
type: 'group',
},
{
id: 'dance-group',
isSelected: false,
lastUpdated: Date.now(),
markedUnread: false,
title: 'Are we dancers? 💃',
type: 'group',
},
];
const defaultArchivedConversations: Array<ConversationListItemPropsType> = [
2020-08-21 16:09:39 +00:00
{
id: 'michelle-archive-convo',
isSelected: false,
lastUpdated: Date.now(),
markedUnread: false,
2020-08-21 16:09:39 +00:00
title: 'Michelle Mercure',
type: 'direct',
},
];
const pinnedConversations: Array<ConversationListItemPropsType> = [
{
id: 'philly-convo',
isPinned: true,
isSelected: false,
lastUpdated: Date.now(),
markedUnread: false,
title: 'Philip Glass',
type: 'direct',
},
{
id: 'robbo-convo',
isPinned: true,
isSelected: false,
lastUpdated: Date.now(),
markedUnread: false,
title: 'Robert Moog',
type: 'direct',
},
];
const defaultModeSpecificProps = {
mode: LeftPaneMode.Inbox as const,
pinnedConversations,
conversations: defaultConversations,
archivedConversations: defaultArchivedConversations,
};
const emptySearchResultsGroup = { isLoading: false, results: [] };
2020-08-21 16:09:39 +00:00
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
2021-03-03 20:09:58 +00:00
cantAddContactToGroup: action('cantAddContactToGroup'),
clearGroupCreationError: action('clearGroupCreationError'),
closeCantAddContactToGroupModal: action('closeCantAddContactToGroupModal'),
closeMaximumGroupSizeModal: action('closeMaximumGroupSizeModal'),
closeRecommendedGroupSizeModal: action('closeRecommendedGroupSizeModal'),
createGroup: action('createGroup'),
2020-08-21 16:09:39 +00:00
i18n,
modeSpecificProps: defaultModeSpecificProps,
2020-08-21 16:09:39 +00:00
openConversationInternal: action('openConversationInternal'),
regionCode: 'US',
2020-08-21 16:09:39 +00:00
renderExpiredBuildDialog: () => <div />,
renderMainHeader: () => <div />,
renderMessageSearchResult: (id: string, style: React.CSSProperties) => (
<MessageSearchResult
body="Lorem ipsum wow"
bodyRanges={[]}
conversationId="marc-convo"
from={defaultConversations[0]}
i18n={i18n}
id={id}
openConversationInternal={action('openConversationInternal')}
sentAt={1587358800000}
snippet="Lorem <<left>>ipsum<<right>> wow"
style={style}
to={defaultConversations[1]}
/>
),
2020-08-21 16:09:39 +00:00
renderNetworkStatus: () => <div />,
renderRelinkDialog: () => <div />,
renderUpdateDialog: () => <div />,
selectedConversationId: undefined,
selectedMessageId: undefined,
setComposeSearchTerm: action('setComposeSearchTerm'),
2021-03-03 20:09:58 +00:00
setComposeGroupAvatar: action('setComposeGroupAvatar'),
setComposeGroupName: action('setComposeGroupName'),
2020-08-21 16:09:39 +00:00
showArchivedConversations: action('showArchivedConversations'),
showInbox: action('showInbox'),
startComposing: action('startComposing'),
2021-03-03 20:09:58 +00:00
showChooseGroupMembers: action('showChooseGroupMembers'),
startNewConversationFromPhoneNumber: action(
'startNewConversationFromPhoneNumber'
),
2021-03-03 20:09:58 +00:00
startSettingGroupMetadata: action('startSettingGroupMetadata'),
toggleConversationInChooseMembers: action(
'toggleConversationInChooseMembers'
),
...overrideProps,
2020-08-21 16:09:39 +00:00
});
// Inbox stories
2020-08-21 16:09:39 +00:00
story.add('Inbox: no conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Inbox,
pinnedConversations: [],
conversations: [],
archivedConversations: [],
},
})}
/>
));
2020-08-21 16:09:39 +00:00
story.add('Inbox: only pinned conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Inbox,
pinnedConversations,
conversations: [],
archivedConversations: [],
},
})}
/>
));
story.add('Inbox: only non-pinned conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Inbox,
pinnedConversations: [],
conversations: defaultConversations,
archivedConversations: [],
},
})}
/>
));
story.add('Inbox: only archived conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Inbox,
pinnedConversations: [],
conversations: [],
archivedConversations: defaultArchivedConversations,
},
})}
/>
));
story.add('Inbox: pinned and archived conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Inbox,
pinnedConversations,
conversations: [],
archivedConversations: defaultArchivedConversations,
},
})}
/>
));
story.add('Inbox: non-pinned and archived conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Inbox,
pinnedConversations: [],
conversations: defaultConversations,
archivedConversations: defaultArchivedConversations,
},
})}
/>
));
2020-08-21 16:09:39 +00:00
story.add('Inbox: pinned and non-pinned conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Inbox,
pinnedConversations,
conversations: defaultConversations,
archivedConversations: [],
},
})}
/>
));
story.add('Inbox: pinned, non-pinned, and archived conversations', () => (
<LeftPane {...createProps()} />
));
// Search stories
story.add('Search: no results when searching everywhere', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Search,
conversationResults: emptySearchResultsGroup,
contactResults: emptySearchResultsGroup,
messageResults: emptySearchResultsGroup,
searchTerm: 'foo bar',
},
})}
/>
));
story.add('Search: no results when searching in a conversation', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Search,
conversationResults: emptySearchResultsGroup,
contactResults: emptySearchResultsGroup,
messageResults: emptySearchResultsGroup,
searchConversationName: 'Bing Bong',
searchTerm: 'foo bar',
},
})}
/>
));
story.add('Search: all results loading', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Search,
conversationResults: { isLoading: true },
contactResults: { isLoading: true },
messageResults: { isLoading: true },
searchTerm: 'foo bar',
},
})}
/>
));
story.add('Search: some results loading', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Search,
conversationResults: {
isLoading: false,
results: defaultConversations,
2020-08-21 16:09:39 +00:00
},
contactResults: { isLoading: true },
messageResults: { isLoading: true },
searchTerm: 'foo bar',
},
})}
/>
));
story.add('Search: has conversations and contacts, but not messages', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Search,
conversationResults: {
isLoading: false,
results: defaultConversations,
2020-08-21 16:09:39 +00:00
},
contactResults: { isLoading: false, results: defaultConversations },
messageResults: { isLoading: false, results: [] },
searchTerm: 'foo bar',
},
})}
/>
));
story.add('Search: all results', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Search,
conversationResults: {
isLoading: false,
results: defaultConversations,
2020-08-21 16:09:39 +00:00
},
contactResults: { isLoading: false, results: defaultConversations },
messageResults: {
isLoading: false,
results: [
{ id: 'msg1', conversationId: 'foo' },
{ id: 'msg2', conversationId: 'bar' },
],
2020-08-21 16:09:39 +00:00
},
searchTerm: 'foo bar',
},
})}
/>
));
// Archived stories
story.add('Archive: no archived conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Archive,
archivedConversations: [],
},
})}
/>
));
story.add('Archive: archived conversations', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Archive,
archivedConversations: defaultConversations,
},
})}
/>
));
// Compose stories
story.add('Compose: no contacts or groups', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Compose,
composeContacts: [],
composeGroups: [],
regionCode: 'US',
searchTerm: '',
},
})}
/>
));
story.add('Compose: some contacts, no groups, no search term', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Compose,
composeContacts: defaultConversations,
composeGroups: [],
regionCode: 'US',
searchTerm: '',
},
})}
/>
));
story.add('Compose: some contacts, no groups, with a search term', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Compose,
composeContacts: defaultConversations,
composeGroups: [],
regionCode: 'US',
searchTerm: 'ar',
},
})}
/>
));
story.add('Compose: some groups, no contacts, no search term', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Compose,
composeContacts: [],
composeGroups: defaultGroups,
regionCode: 'US',
searchTerm: '',
},
})}
/>
));
story.add('Compose: some groups, no contacts, with search term', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Compose,
composeContacts: [],
composeGroups: defaultGroups,
regionCode: 'US',
searchTerm: 'ar',
},
})}
/>
));
story.add('Compose: some contacts, some groups, no search term', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Compose,
composeContacts: defaultConversations,
composeGroups: defaultGroups,
regionCode: 'US',
searchTerm: '',
},
})}
/>
));
story.add('Compose: some contacts, some groups, with a search term', () => (
<LeftPane
{...createProps({
modeSpecificProps: {
mode: LeftPaneMode.Compose,
composeContacts: defaultConversations,
composeGroups: defaultGroups,
regionCode: 'US',
searchTerm: 'ar',
},
})}
/>
));