signal-desktop/ts/components/StoriesTab.tsx

225 lines
7.3 KiB
TypeScript
Raw Normal View History

2022-03-04 21:14:52 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2022-07-06 19:06:20 +00:00
import React, { useState } from 'react';
2022-07-01 00:52:03 +00:00
import type {
ConversationType,
ShowConversationType,
} from '../state/ducks/conversations';
import type {
ConversationStoryType,
MyStoryType,
StoryViewType,
} from '../types/Stories';
2023-08-09 00:53:06 +00:00
import type { LocalizerType, ThemeType } from '../types/Util';
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
import type { ShowToastAction } from '../state/ducks/toast';
2022-08-22 17:44:23 +00:00
import type {
AddStoryData,
2022-08-22 17:44:23 +00:00
ViewUserStoriesActionCreatorType,
ViewStoryActionCreatorType,
} from '../state/ducks/stories';
2022-07-01 00:52:03 +00:00
import { MyStories } from './MyStories';
2022-03-04 21:14:52 +00:00
import { StoriesPane } from './StoriesPane';
2023-08-09 00:53:06 +00:00
import { NavSidebar, NavSidebarActionButton } from './NavSidebar';
import { StoriesAddStoryButton } from './StoriesAddStoryButton';
import { ContextMenu } from './ContextMenu';
import type { WidthBreakpoint } from './_util';
import type { UnreadStats } from '../util/countUnreadStats';
2022-03-04 21:14:52 +00:00
export type PropsType = {
addStoryData: AddStoryData;
2023-08-21 20:12:27 +00:00
otherTabsUnreadStats: UnreadStats;
2022-07-01 00:52:03 +00:00
deleteStoryForEveryone: (story: StoryViewType) => unknown;
getPreferredBadge: PreferredBadgeSelectorType;
hasFailedStorySends: boolean;
hasPendingUpdate: boolean;
2022-11-09 02:38:19 +00:00
hasViewReceiptSetting: boolean;
2022-03-04 21:14:52 +00:00
hiddenStories: Array<ConversationStoryType>;
i18n: LocalizerType;
2022-11-09 02:38:19 +00:00
isStoriesSettingsVisible: boolean;
isViewingStory: boolean;
maxAttachmentSizeInKb: number;
2022-07-01 00:52:03 +00:00
me: ConversationType;
myStories: Array<MyStoryType>;
2023-08-09 00:53:06 +00:00
navTabsCollapsed: boolean;
2022-07-01 00:52:03 +00:00
onForwardStory: (storyId: string) => unknown;
onSaveStory: (story: StoryViewType) => unknown;
2023-08-09 00:53:06 +00:00
onToggleNavTabsCollapse: (navTabsCollapsed: boolean) => void;
2023-02-24 23:18:57 +00:00
onMediaPlaybackStart: () => void;
2023-08-09 00:53:06 +00:00
preferredLeftPaneWidth: number;
2022-03-04 21:14:52 +00:00
preferredWidthFromStorage: number;
2022-03-29 01:10:08 +00:00
queueStoryDownload: (storyId: string) => unknown;
renderStoryCreator: () => JSX.Element;
renderToastManager: (_: {
containerWidthBreakpoint: WidthBreakpoint;
}) => JSX.Element;
retryMessageSend: (messageId: string) => unknown;
2023-08-09 00:53:06 +00:00
savePreferredLeftPaneWidth: (preferredLeftPaneWidth: number) => void;
setAddStoryData: (data: AddStoryData) => unknown;
2022-06-16 19:12:50 +00:00
showConversation: ShowConversationType;
showStoriesSettings: () => unknown;
showToast: ShowToastAction;
2022-03-04 21:14:52 +00:00
stories: Array<ConversationStoryType>;
2023-08-09 00:53:06 +00:00
theme: ThemeType;
2022-03-04 21:14:52 +00:00
toggleHideStories: (conversationId: string) => unknown;
2022-07-06 19:06:20 +00:00
viewStory: ViewStoryActionCreatorType;
2022-11-09 02:38:19 +00:00
viewUserStories: ViewUserStoriesActionCreatorType;
2022-03-04 21:14:52 +00:00
};
2023-08-09 00:53:06 +00:00
export function StoriesTab({
addStoryData,
2023-08-21 20:12:27 +00:00
otherTabsUnreadStats,
2022-07-01 00:52:03 +00:00
deleteStoryForEveryone,
getPreferredBadge,
hasFailedStorySends,
hasPendingUpdate,
2022-11-09 02:38:19 +00:00
hasViewReceiptSetting,
2022-03-04 21:14:52 +00:00
hiddenStories,
i18n,
maxAttachmentSizeInKb,
2022-07-01 00:52:03 +00:00
me,
myStories,
2023-08-09 00:53:06 +00:00
navTabsCollapsed,
2022-07-01 00:52:03 +00:00
onForwardStory,
onSaveStory,
2023-08-09 00:53:06 +00:00
onToggleNavTabsCollapse,
2023-02-24 23:18:57 +00:00
onMediaPlaybackStart,
2023-08-09 00:53:06 +00:00
preferredLeftPaneWidth,
2022-03-29 01:10:08 +00:00
queueStoryDownload,
2022-06-17 00:48:57 +00:00
renderStoryCreator,
renderToastManager,
retryMessageSend,
2023-08-09 00:53:06 +00:00
savePreferredLeftPaneWidth,
setAddStoryData,
2022-06-16 19:12:50 +00:00
showConversation,
showStoriesSettings,
showToast,
2022-03-04 21:14:52 +00:00
stories,
2023-08-09 00:53:06 +00:00
theme,
2022-03-04 21:14:52 +00:00
toggleHideStories,
2022-07-06 19:06:20 +00:00
viewStory,
2022-11-09 02:38:19 +00:00
viewUserStories,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
2022-07-01 00:52:03 +00:00
const [isMyStories, setIsMyStories] = useState(false);
2022-06-17 00:48:57 +00:00
2023-08-09 00:53:06 +00:00
function onAddStory(file?: File) {
if (file) {
setAddStoryData({ type: 'Media', file });
} else {
setAddStoryData({ type: 'Text' });
}
}
2022-03-04 21:14:52 +00:00
return (
2023-08-09 00:53:06 +00:00
<div className="Stories">
{addStoryData && renderStoryCreator()}
2023-08-09 00:53:06 +00:00
{isMyStories && myStories.length ? (
<MyStories
2023-08-21 20:12:27 +00:00
otherTabsUnreadStats={otherTabsUnreadStats}
hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate}
2023-08-09 00:53:06 +00:00
hasViewReceiptSetting={hasViewReceiptSetting}
i18n={i18n}
myStories={myStories}
2023-08-09 16:42:27 +00:00
navTabsCollapsed={navTabsCollapsed}
2023-08-09 00:53:06 +00:00
onBack={() => setIsMyStories(false)}
onDelete={deleteStoryForEveryone}
onForward={onForwardStory}
onSave={onSaveStory}
onMediaPlaybackStart={onMediaPlaybackStart}
2023-08-09 16:42:27 +00:00
onToggleNavTabsCollapse={onToggleNavTabsCollapse}
preferredLeftPaneWidth={preferredLeftPaneWidth}
2023-08-09 00:53:06 +00:00
queueStoryDownload={queueStoryDownload}
retryMessageSend={retryMessageSend}
renderToastManager={renderToastManager}
2023-08-09 16:42:27 +00:00
savePreferredLeftPaneWidth={savePreferredLeftPaneWidth}
theme={theme}
2023-08-09 00:53:06 +00:00
viewStory={viewStory}
/>
) : (
<NavSidebar
2023-10-19 18:08:47 +00:00
title={i18n('icu:Stories__title')}
2023-08-09 00:53:06 +00:00
i18n={i18n}
hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate}
2023-08-09 00:53:06 +00:00
navTabsCollapsed={navTabsCollapsed}
onToggleNavTabsCollapse={onToggleNavTabsCollapse}
preferredLeftPaneWidth={preferredLeftPaneWidth}
requiresFullWidth
savePreferredLeftPaneWidth={savePreferredLeftPaneWidth}
2023-08-21 20:12:27 +00:00
otherTabsUnreadStats={otherTabsUnreadStats}
renderToastManager={renderToastManager}
2023-08-09 00:53:06 +00:00
actions={
<>
<StoriesAddStoryButton
i18n={i18n}
maxAttachmentSizeInKb={maxAttachmentSizeInKb}
moduleClassName="Stories__pane__add-story"
onAddStory={onAddStory}
showToast={showToast}
/>
<ContextMenu
i18n={i18n}
menuOptions={[
{
label: i18n('icu:StoriesSettings__context-menu'),
onClick: showStoriesSettings,
},
]}
moduleClassName="Stories__pane__settings"
popperOptions={{
placement: 'bottom',
strategy: 'absolute',
}}
portalToRoot
>
{({ openMenu, onKeyDown }) => {
return (
<NavSidebarActionButton
onClick={openMenu}
onKeyDown={onKeyDown}
icon={<span className="StoriesTab__MoreActionsIcon" />}
label={i18n('icu:StoriesTab__MoreActionsLabel')}
/>
);
}}
</ContextMenu>
</>
}
>
2022-08-04 19:23:24 +00:00
<StoriesPane
getPreferredBadge={getPreferredBadge}
hiddenStories={hiddenStories}
i18n={i18n}
maxAttachmentSizeInKb={maxAttachmentSizeInKb}
2022-08-04 19:23:24 +00:00
me={me}
myStories={myStories}
2023-08-09 00:53:06 +00:00
onAddStory={onAddStory}
2022-08-04 19:23:24 +00:00
onMyStoriesClicked={() => {
if (myStories.length) {
setIsMyStories(true);
} else {
setAddStoryData({ type: 'Text' });
}
}}
onStoriesSettings={showStoriesSettings}
2023-02-24 23:18:57 +00:00
onMediaPlaybackStart={onMediaPlaybackStart}
2022-08-04 19:23:24 +00:00
queueStoryDownload={queueStoryDownload}
showConversation={showConversation}
showToast={showToast}
2022-08-04 19:23:24 +00:00
stories={stories}
2023-08-09 00:53:06 +00:00
theme={theme}
2022-08-04 19:23:24 +00:00
toggleHideStories={toggleHideStories}
viewUserStories={viewUserStories}
/>
2023-08-09 00:53:06 +00:00
</NavSidebar>
)}
2022-03-04 21:14:52 +00:00
<div className="Stories__placeholder">
<div className="Stories__placeholder__stories" />
2023-03-30 00:03:25 +00:00
{i18n('icu:Stories__placeholder--text')}
2022-03-04 21:14:52 +00:00
</div>
</div>
);
2022-11-18 00:45:19 +00:00
}