signal-desktop/ts/state/smart/StoriesTab.tsx

152 lines
5.4 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
import React, { memo, useCallback, useEffect } from 'react';
2022-03-04 21:14:52 +00:00
import { useSelector } from 'react-redux';
2022-06-17 00:48:57 +00:00
import { SmartStoryCreator } from './StoryCreator';
import { SmartToastManager } from './ToastManager';
import type { WidthBreakpoint } from '../../components/_util';
2023-08-09 00:53:06 +00:00
import { StoriesTab } from '../../components/StoriesTab';
import { getMaximumOutgoingAttachmentSizeInKb } from '../../types/AttachmentSize';
import type { ConfigKeyType } from '../../RemoteConfig';
2022-07-01 00:52:03 +00:00
import { getMe } from '../selectors/conversations';
2023-08-09 00:53:06 +00:00
import { getIntl, getTheme } from '../selectors/user';
import { getPreferredBadgeSelector } from '../selectors/badges';
import {
2022-10-25 22:18:42 +00:00
getHasStoryViewReceiptSetting,
2023-08-09 00:53:06 +00:00
getNavTabsCollapsed,
getPreferredLeftPaneWidth,
getRemoteConfig,
} from '../selectors/items';
import {
getAddStoryData,
getHasAnyFailedStorySends,
getSelectedStoryData,
getStories,
} from '../selectors/stories';
2022-03-04 21:14:52 +00:00
import { useConversationsActions } from '../ducks/conversations';
2022-07-01 00:52:03 +00:00
import { useGlobalModalActions } from '../ducks/globalModals';
import { useStoriesActions } from '../ducks/stories';
import { useToastActions } from '../ducks/toast';
2023-02-24 23:18:57 +00:00
import { useAudioPlayerActions } from '../ducks/audioPlayer';
2023-08-09 00:53:06 +00:00
import { useItemsActions } from '../ducks/items';
import { getHasPendingUpdate } from '../selectors/updates';
2023-08-21 20:12:27 +00:00
import { getOtherTabsUnreadStats } from '../selectors/nav';
import { getIsStoriesSettingsVisible } from '../selectors/globalModals';
import type { StoryViewType } from '../../types/Stories';
2024-05-22 16:24:27 +00:00
import { ForwardMessagesModalType } from '../../components/ForwardMessagesModal';
2022-03-04 21:14:52 +00:00
function renderStoryCreator(): JSX.Element {
return <SmartStoryCreator />;
2022-06-17 00:48:57 +00:00
}
function renderToastManager(props: {
containerWidthBreakpoint: WidthBreakpoint;
}): JSX.Element {
return <SmartToastManager disableMegaphone {...props} />;
}
export const SmartStoriesTab = memo(function SmartStoriesTab() {
2022-03-04 21:14:52 +00:00
const storiesActions = useStoriesActions();
const {
retryMessageSend,
saveAttachment,
showConversation,
toggleHideStories,
} = useConversationsActions();
2023-03-20 22:23:53 +00:00
const { showStoriesSettings, toggleForwardMessagesModal } =
useGlobalModalActions();
const { showToast } = useToastActions();
2022-03-04 21:14:52 +00:00
const i18n = useSelector(getIntl);
const preferredWidthFromStorage = useSelector(getPreferredLeftPaneWidth);
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
const addStoryData = useSelector(getAddStoryData);
2022-07-01 00:52:03 +00:00
const { hiddenStories, myStories, stories } = useSelector(getStories);
const me = useSelector(getMe);
const selectedStoryData = useSelector(getSelectedStoryData);
const isStoriesSettingsVisible = useSelector(getIsStoriesSettingsVisible);
2022-10-25 22:18:42 +00:00
const hasViewReceiptSetting = useSelector(getHasStoryViewReceiptSetting);
const hasPendingUpdate = useSelector(getHasPendingUpdate);
const hasFailedStorySends = useSelector(getHasAnyFailedStorySends);
2023-08-21 20:12:27 +00:00
const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats);
const remoteConfig = useSelector(getRemoteConfig);
const maxAttachmentSizeInKb = getMaximumOutgoingAttachmentSizeInKb(
(name: ConfigKeyType) => {
const value = remoteConfig[name]?.value;
return value ? String(value) : undefined;
}
);
2023-02-24 23:18:57 +00:00
const { pauseVoiceNotePlayer } = useAudioPlayerActions();
2023-08-09 00:53:06 +00:00
const preferredLeftPaneWidth = useSelector(getPreferredLeftPaneWidth);
const navTabsCollapsed = useSelector(getNavTabsCollapsed);
const { savePreferredLeftPaneWidth, toggleNavTabsCollapse } =
useItemsActions();
const theme = useSelector(getTheme);
useEffect(() => {
storiesActions.markStoriesTabViewed();
return () => {
storiesActions.clearStoriesTabState();
};
}, [storiesActions]);
2022-03-04 21:14:52 +00:00
const handleForwardStory = useCallback(
(messageId: string) => {
2024-05-22 16:24:27 +00:00
toggleForwardMessagesModal({
type: ForwardMessagesModalType.Forward,
messageIds: [messageId],
});
},
[toggleForwardMessagesModal]
);
const handleSaveStory = useCallback(
(story: StoryViewType) => {
if (story.attachment) {
saveAttachment(story.attachment, story.timestamp);
}
},
[saveAttachment]
);
2022-03-04 21:14:52 +00:00
return (
2023-08-09 00:53:06 +00:00
<StoriesTab
2023-08-21 20:12:27 +00:00
otherTabsUnreadStats={otherTabsUnreadStats}
addStoryData={addStoryData}
getPreferredBadge={getPreferredBadge}
hasFailedStorySends={hasFailedStorySends}
hasPendingUpdate={hasPendingUpdate}
2022-03-04 21:14:52 +00:00
hiddenStories={hiddenStories}
i18n={i18n}
maxAttachmentSizeInKb={maxAttachmentSizeInKb}
2022-07-01 00:52:03 +00:00
me={me}
myStories={myStories}
2023-08-09 00:53:06 +00:00
navTabsCollapsed={navTabsCollapsed}
onForwardStory={handleForwardStory}
onSaveStory={handleSaveStory}
2023-08-09 00:53:06 +00:00
onToggleNavTabsCollapse={toggleNavTabsCollapse}
2023-02-24 23:18:57 +00:00
onMediaPlaybackStart={pauseVoiceNotePlayer}
2023-08-09 00:53:06 +00:00
preferredLeftPaneWidth={preferredLeftPaneWidth}
2022-03-04 21:14:52 +00:00
preferredWidthFromStorage={preferredWidthFromStorage}
2022-06-17 00:48:57 +00:00
renderStoryCreator={renderStoryCreator}
renderToastManager={renderToastManager}
retryMessageSend={retryMessageSend}
2023-08-09 00:53:06 +00:00
savePreferredLeftPaneWidth={savePreferredLeftPaneWidth}
2022-06-16 19:12:50 +00:00
showConversation={showConversation}
showStoriesSettings={showStoriesSettings}
showToast={showToast}
2022-03-04 21:14:52 +00:00
stories={stories}
2023-08-09 00:53:06 +00:00
theme={theme}
2022-03-04 21:14:52 +00:00
toggleHideStories={toggleHideStories}
isViewingStory={selectedStoryData !== undefined}
isStoriesSettingsVisible={isStoriesSettingsVisible}
2022-10-25 22:18:42 +00:00
hasViewReceiptSetting={hasViewReceiptSetting}
2022-03-04 21:14:52 +00:00
{...storiesActions}
/>
);
});