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-03-04 21:14:52 +00:00
|
|
|
import classNames from 'classnames';
|
2022-07-01 00:52:03 +00:00
|
|
|
import type {
|
|
|
|
ConversationType,
|
|
|
|
ShowConversationType,
|
|
|
|
} from '../state/ducks/conversations';
|
|
|
|
import type {
|
|
|
|
ConversationStoryType,
|
|
|
|
MyStoryType,
|
|
|
|
StoryViewType,
|
|
|
|
} from '../types/Stories';
|
2022-03-04 21:14:52 +00:00
|
|
|
import type { LocalizerType } from '../types/Util';
|
2022-07-29 00:16:30 +00:00
|
|
|
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
|
2022-08-12 23:44:10 +00:00
|
|
|
import type { ShowToastActionCreatorType } from '../state/ducks/toast';
|
2022-08-22 17:44:23 +00:00
|
|
|
import type {
|
2022-11-02 00:36:16 +00:00
|
|
|
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';
|
|
|
|
import { Theme, themeClassName } from '../util/theme';
|
|
|
|
import { getWidthFromPreferredWidth } from '../util/leftPaneWidth';
|
2022-09-26 20:28:40 +00:00
|
|
|
import { useEscapeHandling } from '../hooks/useEscapeHandling';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
export type PropsType = {
|
2022-11-02 00:36:16 +00:00
|
|
|
addStoryData: AddStoryData;
|
2022-07-01 00:52:03 +00:00
|
|
|
deleteStoryForEveryone: (story: StoryViewType) => unknown;
|
2022-07-29 00:16:30 +00:00
|
|
|
getPreferredBadge: PreferredBadgeSelectorType;
|
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;
|
2022-07-01 00:52:03 +00:00
|
|
|
me: ConversationType;
|
|
|
|
myStories: Array<MyStoryType>;
|
|
|
|
onForwardStory: (storyId: string) => unknown;
|
|
|
|
onSaveStory: (story: StoryViewType) => unknown;
|
2022-03-04 21:14:52 +00:00
|
|
|
preferredWidthFromStorage: number;
|
2022-03-29 01:10:08 +00:00
|
|
|
queueStoryDownload: (storyId: string) => unknown;
|
2022-11-02 00:36:16 +00:00
|
|
|
renderStoryCreator: () => JSX.Element;
|
2022-12-20 01:04:47 +00:00
|
|
|
retryMessageSend: (messageId: string) => unknown;
|
2022-11-02 00:36:16 +00:00
|
|
|
setAddStoryData: (data: AddStoryData) => unknown;
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation: ShowConversationType;
|
2022-07-21 00:07:09 +00:00
|
|
|
showStoriesSettings: () => unknown;
|
2022-08-12 23:44:10 +00:00
|
|
|
showToast: ShowToastActionCreatorType;
|
2022-03-04 21:14:52 +00:00
|
|
|
stories: Array<ConversationStoryType>;
|
|
|
|
toggleHideStories: (conversationId: string) => unknown;
|
|
|
|
toggleStoriesView: () => 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
|
|
|
};
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function Stories({
|
2022-11-02 00:36:16 +00:00
|
|
|
addStoryData,
|
2022-07-01 00:52:03 +00:00
|
|
|
deleteStoryForEveryone,
|
2022-07-29 00:16:30 +00:00
|
|
|
getPreferredBadge,
|
2022-11-09 02:38:19 +00:00
|
|
|
hasViewReceiptSetting,
|
2022-03-04 21:14:52 +00:00
|
|
|
hiddenStories,
|
|
|
|
i18n,
|
2022-11-09 02:38:19 +00:00
|
|
|
isStoriesSettingsVisible,
|
|
|
|
isViewingStory,
|
2022-07-01 00:52:03 +00:00
|
|
|
me,
|
|
|
|
myStories,
|
|
|
|
onForwardStory,
|
|
|
|
onSaveStory,
|
2022-03-04 21:14:52 +00:00
|
|
|
preferredWidthFromStorage,
|
2022-03-29 01:10:08 +00:00
|
|
|
queueStoryDownload,
|
2022-06-17 00:48:57 +00:00
|
|
|
renderStoryCreator,
|
2022-12-20 01:04:47 +00:00
|
|
|
retryMessageSend,
|
2022-11-02 00:36:16 +00:00
|
|
|
setAddStoryData,
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation,
|
2022-07-21 00:07:09 +00:00
|
|
|
showStoriesSettings,
|
2022-08-12 23:44:10 +00:00
|
|
|
showToast,
|
2022-03-04 21:14:52 +00:00
|
|
|
stories,
|
|
|
|
toggleHideStories,
|
|
|
|
toggleStoriesView,
|
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-03-04 21:14:52 +00:00
|
|
|
const width = getWidthFromPreferredWidth(preferredWidthFromStorage, {
|
|
|
|
requiresFullWidth: true,
|
|
|
|
});
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
const [isMyStories, setIsMyStories] = useState(false);
|
2022-06-17 00:48:57 +00:00
|
|
|
|
2022-09-26 20:28:40 +00:00
|
|
|
// only handle ESC if not showing a child that handles their own ESC
|
|
|
|
useEscapeHandling(
|
|
|
|
(isMyStories && myStories.length) ||
|
|
|
|
isViewingStory ||
|
2022-10-12 16:14:35 +00:00
|
|
|
isStoriesSettingsVisible ||
|
|
|
|
addStoryData
|
2022-09-26 20:28:40 +00:00
|
|
|
? undefined
|
|
|
|
: toggleStoriesView
|
|
|
|
);
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
return (
|
|
|
|
<div className={classNames('Stories', themeClassName(Theme.Dark))}>
|
2022-11-02 00:36:16 +00:00
|
|
|
{addStoryData && renderStoryCreator()}
|
2022-08-04 19:23:24 +00:00
|
|
|
<div className="Stories__pane" style={{ width }}>
|
|
|
|
{isMyStories && myStories.length ? (
|
|
|
|
<MyStories
|
2022-11-16 22:10:11 +00:00
|
|
|
hasViewReceiptSetting={hasViewReceiptSetting}
|
2022-08-04 19:23:24 +00:00
|
|
|
i18n={i18n}
|
|
|
|
myStories={myStories}
|
|
|
|
onBack={() => setIsMyStories(false)}
|
|
|
|
onDelete={deleteStoryForEveryone}
|
|
|
|
onForward={onForwardStory}
|
|
|
|
onSave={onSaveStory}
|
|
|
|
queueStoryDownload={queueStoryDownload}
|
2022-12-20 01:04:47 +00:00
|
|
|
retryMessageSend={retryMessageSend}
|
2022-08-04 19:23:24 +00:00
|
|
|
viewStory={viewStory}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<StoriesPane
|
|
|
|
getPreferredBadge={getPreferredBadge}
|
|
|
|
hiddenStories={hiddenStories}
|
|
|
|
i18n={i18n}
|
|
|
|
me={me}
|
|
|
|
myStories={myStories}
|
|
|
|
onAddStory={file =>
|
|
|
|
file
|
|
|
|
? setAddStoryData({ type: 'Media', file })
|
|
|
|
: setAddStoryData({ type: 'Text' })
|
|
|
|
}
|
|
|
|
onMyStoriesClicked={() => {
|
|
|
|
if (myStories.length) {
|
|
|
|
setIsMyStories(true);
|
|
|
|
} else {
|
|
|
|
setAddStoryData({ type: 'Text' });
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onStoriesSettings={showStoriesSettings}
|
|
|
|
queueStoryDownload={queueStoryDownload}
|
|
|
|
showConversation={showConversation}
|
2022-08-12 23:44:10 +00:00
|
|
|
showToast={showToast}
|
2022-08-04 19:23:24 +00:00
|
|
|
stories={stories}
|
|
|
|
toggleHideStories={toggleHideStories}
|
|
|
|
toggleStoriesView={toggleStoriesView}
|
|
|
|
viewUserStories={viewUserStories}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-03-04 21:14:52 +00:00
|
|
|
<div className="Stories__placeholder">
|
|
|
|
<div className="Stories__placeholder__stories" />
|
|
|
|
{i18n('Stories__placeholder--text')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|