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

130 lines
4.5 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 from 'react';
import { useSelector } from 'react-redux';
2022-07-06 19:06:20 +00:00
import type { GetConversationByIdType } from '../selectors/conversations';
2022-03-04 21:14:52 +00:00
import type { LocalizerType } from '../../types/Util';
import type { StateType } from '../reducer';
2022-07-06 19:06:20 +00:00
import type { SelectedStoryDataType } from '../ducks/stories';
2022-03-04 21:14:52 +00:00
import { StoryViewer } from '../../components/StoryViewer';
import { ToastType, useToastActions } from '../ducks/toast';
2022-07-06 19:06:20 +00:00
import { getConversationSelector } from '../selectors/conversations';
2022-03-04 21:14:52 +00:00
import {
getEmojiSkinTone,
2022-05-06 19:02:44 +00:00
getHasAllStoriesMuted,
getHasReadReceiptSetting,
2022-03-04 21:14:52 +00:00
getPreferredReactionEmoji,
} from '../selectors/items';
import { getIntl } from '../selectors/user';
import { getPreferredBadgeSelector } from '../selectors/badges';
2022-07-06 19:06:20 +00:00
import {
getSelectedStoryData,
getStoryReplies,
getStoryByIdSelector,
2022-07-06 19:06:20 +00:00
} from '../selectors/stories';
import { isInFullScreenCall } from '../selectors/calling';
2022-03-04 21:14:52 +00:00
import { renderEmojiPicker } from './renderEmojiPicker';
2022-07-06 19:06:20 +00:00
import { strictAssert } from '../../util/assert';
2022-03-04 21:14:52 +00:00
import { useActions as useEmojisActions } from '../ducks/emojis';
import { useActions as useItemsActions } from '../ducks/items';
import { useConversationsActions } from '../ducks/conversations';
2022-03-04 21:14:52 +00:00
import { useRecentEmojis } from '../selectors/emojis';
import { useStoriesActions } from '../ducks/stories';
2022-07-06 19:06:20 +00:00
export function SmartStoryViewer(): JSX.Element | null {
2022-03-04 21:14:52 +00:00
const storiesActions = useStoriesActions();
2022-05-06 19:02:44 +00:00
const { onSetSkinTone, toggleHasAllStoriesMuted } = useItemsActions();
2022-03-04 21:14:52 +00:00
const { onUseEmoji } = useEmojisActions();
2022-06-16 19:12:50 +00:00
const { showConversation, toggleHideStories } = useConversationsActions();
const { showToast } = useToastActions();
2022-03-04 21:14:52 +00:00
const i18n = useSelector<StateType, LocalizerType>(getIntl);
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
const preferredReactionEmoji = useSelector<StateType, Array<string>>(
getPreferredReactionEmoji
);
2022-07-06 19:06:20 +00:00
const selectedStoryData = useSelector<
2022-04-15 00:08:46 +00:00
StateType,
2022-07-06 19:06:20 +00:00
SelectedStoryDataType | undefined
>(getSelectedStoryData);
2022-04-15 00:08:46 +00:00
2022-07-06 19:06:20 +00:00
strictAssert(selectedStoryData, 'StoryViewer: !selectedStoryData');
const conversationSelector = useSelector<StateType, GetConversationByIdType>(
getConversationSelector
);
const getStoryById = useSelector(getStoryByIdSelector);
const storyInfo = getStoryById(
2022-07-06 19:06:20 +00:00
conversationSelector,
selectedStoryData.messageId
);
strictAssert(
storyInfo,
'StoryViewer: selected story does not exist in stories'
2022-07-06 19:06:20 +00:00
);
const { conversationStory, distributionList, storyView } = storyInfo;
2022-03-04 21:14:52 +00:00
const recentEmojis = useRecentEmojis();
const skinTone = useSelector<StateType, number>(getEmojiSkinTone);
2022-04-15 00:08:46 +00:00
const replyState = useSelector(getStoryReplies);
2022-05-06 19:02:44 +00:00
const hasAllStoriesMuted = useSelector<StateType, boolean>(
getHasAllStoriesMuted
);
2022-03-04 21:14:52 +00:00
const hasActiveCall = useSelector(isInFullScreenCall);
const hasReadReceiptSetting = useSelector<StateType, boolean>(
getHasReadReceiptSetting
);
2022-03-04 21:14:52 +00:00
return (
<StoryViewer
2022-07-06 19:06:20 +00:00
currentIndex={selectedStoryData.currentIndex}
distributionList={distributionList}
2022-03-04 21:14:52 +00:00
getPreferredBadge={getPreferredBadge}
2022-07-06 19:06:20 +00:00
group={conversationStory.group}
hasActiveCall={hasActiveCall}
2022-05-06 19:02:44 +00:00
hasAllStoriesMuted={hasAllStoriesMuted}
hasReadReceiptSetting={hasReadReceiptSetting}
2022-03-04 21:14:52 +00:00
i18n={i18n}
2022-07-06 19:06:20 +00:00
numStories={selectedStoryData.numStories}
onHideStory={toggleHideStories}
onGoToConversation={senderId => {
2022-06-16 19:12:50 +00:00
showConversation({ conversationId: senderId });
storiesActions.toggleStoriesView();
}}
2022-03-04 21:14:52 +00:00
onReactToStory={async (emoji, story) => {
2022-04-28 22:06:28 +00:00
const { messageId } = story;
storiesActions.reactToStory(emoji, messageId);
2022-03-04 21:14:52 +00:00
}}
onReplyToStory={(message, mentions, timestamp, story) => {
storiesActions.replyToStory(
2022-07-06 19:06:20 +00:00
conversationStory.conversationId,
2022-03-04 21:14:52 +00:00
message,
mentions,
timestamp,
story
);
}}
onSetSkinTone={onSetSkinTone}
onTextTooLong={() => showToast(ToastType.MessageBodyTooLong)}
2022-03-04 21:14:52 +00:00
onUseEmoji={onUseEmoji}
preferredReactionEmoji={preferredReactionEmoji}
recentEmojis={recentEmojis}
renderEmojiPicker={renderEmojiPicker}
2022-04-15 00:08:46 +00:00
replyState={replyState}
2022-07-25 18:55:44 +00:00
shouldShowDetailsModal={selectedStoryData.shouldShowDetailsModal}
showToast={showToast}
2022-03-04 21:14:52 +00:00
skinTone={skinTone}
2022-07-06 19:06:20 +00:00
story={storyView}
2022-08-22 17:44:23 +00:00
storyViewMode={selectedStoryData.storyViewMode}
2022-05-06 19:02:44 +00:00
toggleHasAllStoriesMuted={toggleHasAllStoriesMuted}
2022-03-04 21:14:52 +00:00
{...storiesActions}
/>
);
}