// Copyright 2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useState } from 'react'; import type { ConversationType, ShowConversationType, } from '../state/ducks/conversations'; import type { ConversationStoryType, MyStoryType, StoryViewType, } from '../types/Stories'; import type { LocalizerType, ThemeType } from '../types/Util'; import type { PreferredBadgeSelectorType } from '../state/selectors/badges'; import type { ShowToastAction } from '../state/ducks/toast'; import type { AddStoryData, ViewUserStoriesActionCreatorType, ViewStoryActionCreatorType, } from '../state/ducks/stories'; import { MyStories } from './MyStories'; import { StoriesPane } from './StoriesPane'; import { NavSidebar, NavSidebarActionButton } from './NavSidebar'; import { StoriesAddStoryButton } from './StoriesAddStoryButton'; import { ContextMenu } from './ContextMenu'; import type { UnreadStats } from '../util/countUnreadStats'; export type PropsType = { addStoryData: AddStoryData; appUnreadStats: UnreadStats; deleteStoryForEveryone: (story: StoryViewType) => unknown; getPreferredBadge: PreferredBadgeSelectorType; hasFailedStorySends: boolean; hasPendingUpdate: boolean; hasViewReceiptSetting: boolean; hiddenStories: Array; i18n: LocalizerType; isStoriesSettingsVisible: boolean; isViewingStory: boolean; maxAttachmentSizeInKb: number; me: ConversationType; myStories: Array; navTabsCollapsed: boolean; onForwardStory: (storyId: string) => unknown; onSaveStory: (story: StoryViewType) => unknown; onToggleNavTabsCollapse: (navTabsCollapsed: boolean) => void; onMediaPlaybackStart: () => void; preferredLeftPaneWidth: number; preferredWidthFromStorage: number; queueStoryDownload: (storyId: string) => unknown; renderStoryCreator: () => JSX.Element; retryMessageSend: (messageId: string) => unknown; savePreferredLeftPaneWidth: (preferredLeftPaneWidth: number) => void; setAddStoryData: (data: AddStoryData) => unknown; showConversation: ShowConversationType; showStoriesSettings: () => unknown; showToast: ShowToastAction; stories: Array; theme: ThemeType; toggleHideStories: (conversationId: string) => unknown; viewStory: ViewStoryActionCreatorType; viewUserStories: ViewUserStoriesActionCreatorType; }; export function StoriesTab({ addStoryData, appUnreadStats, deleteStoryForEveryone, getPreferredBadge, hasFailedStorySends, hasPendingUpdate, hasViewReceiptSetting, hiddenStories, i18n, maxAttachmentSizeInKb, me, myStories, navTabsCollapsed, onForwardStory, onSaveStory, onToggleNavTabsCollapse, onMediaPlaybackStart, preferredLeftPaneWidth, queueStoryDownload, renderStoryCreator, retryMessageSend, savePreferredLeftPaneWidth, setAddStoryData, showConversation, showStoriesSettings, showToast, stories, theme, toggleHideStories, viewStory, viewUserStories, }: PropsType): JSX.Element { const [isMyStories, setIsMyStories] = useState(false); function onAddStory(file?: File) { if (file) { setAddStoryData({ type: 'Media', file }); } else { setAddStoryData({ type: 'Text' }); } } return (
{addStoryData && renderStoryCreator()} {isMyStories && myStories.length ? ( setIsMyStories(false)} onDelete={deleteStoryForEveryone} onForward={onForwardStory} onSave={onSaveStory} onMediaPlaybackStart={onMediaPlaybackStart} onToggleNavTabsCollapse={onToggleNavTabsCollapse} preferredLeftPaneWidth={preferredLeftPaneWidth} queueStoryDownload={queueStoryDownload} retryMessageSend={retryMessageSend} savePreferredLeftPaneWidth={savePreferredLeftPaneWidth} theme={theme} viewStory={viewStory} /> ) : ( {({ openMenu, onKeyDown }) => { return ( } label={i18n('icu:StoriesTab__MoreActionsLabel')} /> ); }} } > { if (myStories.length) { setIsMyStories(true); } else { setAddStoryData({ type: 'Text' }); } }} onStoriesSettings={showStoriesSettings} onMediaPlaybackStart={onMediaPlaybackStart} queueStoryDownload={queueStoryDownload} showConversation={showConversation} showToast={showToast} stories={stories} theme={theme} toggleHideStories={toggleHideStories} viewUserStories={viewUserStories} /> )}
{i18n('icu:Stories__placeholder--text')}
); }