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';
|
|
|
|
|
|
|
|
import type { LocalizerType } from '../../types/Util';
|
|
|
|
import type { StateType } from '../reducer';
|
2022-06-17 00:48:57 +00:00
|
|
|
import type { PropsType as SmartStoryCreatorPropsType } from './StoryCreator';
|
|
|
|
import { SmartStoryCreator } from './StoryCreator';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { Stories } from '../../components/Stories';
|
2022-07-01 00:52:03 +00:00
|
|
|
import { getMe } from '../selectors/conversations';
|
2022-07-06 19:06:20 +00:00
|
|
|
import { getIntl } from '../selectors/user';
|
2022-07-29 00:16:30 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { getPreferredLeftPaneWidth } from '../selectors/items';
|
2022-08-19 18:05:31 +00:00
|
|
|
import { getStories, shouldShowStoriesView } from '../selectors/stories';
|
2022-07-01 00:52:03 +00:00
|
|
|
import { saveAttachment } from '../../util/saveAttachment';
|
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';
|
2022-08-12 23:44:10 +00:00
|
|
|
import { useToastActions } from '../ducks/toast';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-06-17 00:48:57 +00:00
|
|
|
function renderStoryCreator({
|
2022-08-04 19:23:24 +00:00
|
|
|
file,
|
2022-06-17 00:48:57 +00:00
|
|
|
onClose,
|
|
|
|
}: SmartStoryCreatorPropsType): JSX.Element {
|
2022-08-04 19:23:24 +00:00
|
|
|
return <SmartStoryCreator file={file} onClose={onClose} />;
|
2022-06-17 00:48:57 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
export function SmartStories(): JSX.Element | null {
|
|
|
|
const storiesActions = useStoriesActions();
|
2022-06-16 19:12:50 +00:00
|
|
|
const { showConversation, toggleHideStories } = useConversationsActions();
|
2022-07-21 00:07:09 +00:00
|
|
|
const { showStoriesSettings, toggleForwardMessageModal } =
|
|
|
|
useGlobalModalActions();
|
2022-08-12 23:44:10 +00:00
|
|
|
const { showToast } = useToastActions();
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
const i18n = useSelector<StateType, LocalizerType>(getIntl);
|
|
|
|
|
|
|
|
const isShowingStoriesView = useSelector<StateType, boolean>(
|
2022-08-19 18:05:31 +00:00
|
|
|
shouldShowStoriesView
|
2022-03-04 21:14:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const preferredWidthFromStorage = useSelector<StateType, number>(
|
|
|
|
getPreferredLeftPaneWidth
|
|
|
|
);
|
2022-07-29 00:16:30 +00:00
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
const { hiddenStories, myStories, stories } = useSelector(getStories);
|
|
|
|
|
|
|
|
const me = useSelector(getMe);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
if (!isShowingStoriesView) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Stories
|
2022-07-29 00:16:30 +00:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2022-03-04 21:14:52 +00:00
|
|
|
hiddenStories={hiddenStories}
|
|
|
|
i18n={i18n}
|
2022-07-01 00:52:03 +00:00
|
|
|
me={me}
|
|
|
|
myStories={myStories}
|
|
|
|
onForwardStory={storyId => {
|
|
|
|
toggleForwardMessageModal(storyId);
|
|
|
|
}}
|
|
|
|
onSaveStory={story => {
|
|
|
|
if (story.attachment) {
|
|
|
|
saveAttachment(story.attachment, story.timestamp);
|
|
|
|
}
|
|
|
|
}}
|
2022-03-04 21:14:52 +00:00
|
|
|
preferredWidthFromStorage={preferredWidthFromStorage}
|
2022-06-17 00:48:57 +00:00
|
|
|
renderStoryCreator={renderStoryCreator}
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation={showConversation}
|
2022-07-21 00:07:09 +00:00
|
|
|
showStoriesSettings={showStoriesSettings}
|
2022-08-12 23:44:10 +00:00
|
|
|
showToast={showToast}
|
2022-03-04 21:14:52 +00:00
|
|
|
stories={stories}
|
|
|
|
toggleHideStories={toggleHideStories}
|
|
|
|
{...storiesActions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|