Update selectedStoryData whenever its story changes
This commit is contained in:
parent
58aaf1d0e7
commit
c3bb3b152e
5 changed files with 53 additions and 19 deletions
|
@ -9,7 +9,6 @@ import classNames from 'classnames';
|
||||||
import type { ExecuteMenuRoleType } from './TitleBarContainer';
|
import type { ExecuteMenuRoleType } from './TitleBarContainer';
|
||||||
import type { LocaleMessagesType } from '../types/I18N';
|
import type { LocaleMessagesType } from '../types/I18N';
|
||||||
import type { MenuOptionsType, MenuActionType } from '../types/menu';
|
import type { MenuOptionsType, MenuActionType } from '../types/menu';
|
||||||
import type { SelectedStoryDataType } from '../state/ducks/stories';
|
|
||||||
import type { ToastType } from '../state/ducks/toast';
|
import type { ToastType } from '../state/ducks/toast';
|
||||||
import { AppViewType } from '../state/ducks/app';
|
import { AppViewType } from '../state/ducks/app';
|
||||||
import { Inbox } from './Inbox';
|
import { Inbox } from './Inbox';
|
||||||
|
@ -30,7 +29,7 @@ type PropsType = {
|
||||||
renderGlobalModalContainer: () => JSX.Element;
|
renderGlobalModalContainer: () => JSX.Element;
|
||||||
isShowingStoriesView: boolean;
|
isShowingStoriesView: boolean;
|
||||||
renderStories: () => JSX.Element;
|
renderStories: () => JSX.Element;
|
||||||
selectedStoryData?: SelectedStoryDataType;
|
hasSelectedStoryData: boolean;
|
||||||
renderStoryViewer: () => JSX.Element;
|
renderStoryViewer: () => JSX.Element;
|
||||||
requestVerification: (
|
requestVerification: (
|
||||||
type: 'sms' | 'voice',
|
type: 'sms' | 'voice',
|
||||||
|
@ -59,6 +58,7 @@ export const App = ({
|
||||||
executeMenuRole,
|
executeMenuRole,
|
||||||
getPreferredBadge,
|
getPreferredBadge,
|
||||||
hasInitialLoadCompleted,
|
hasInitialLoadCompleted,
|
||||||
|
hasSelectedStoryData,
|
||||||
hideMenuBar,
|
hideMenuBar,
|
||||||
hideToast,
|
hideToast,
|
||||||
i18n,
|
i18n,
|
||||||
|
@ -81,7 +81,6 @@ export const App = ({
|
||||||
requestVerification,
|
requestVerification,
|
||||||
selectedConversationId,
|
selectedConversationId,
|
||||||
selectedMessage,
|
selectedMessage,
|
||||||
selectedStoryData,
|
|
||||||
showConversation,
|
showConversation,
|
||||||
showWhatsNewModal,
|
showWhatsNewModal,
|
||||||
theme,
|
theme,
|
||||||
|
@ -181,7 +180,7 @@ export const App = ({
|
||||||
{renderGlobalModalContainer()}
|
{renderGlobalModalContainer()}
|
||||||
{renderCallManager()}
|
{renderCallManager()}
|
||||||
{isShowingStoriesView && renderStories()}
|
{isShowingStoriesView && renderStories()}
|
||||||
{selectedStoryData && renderStoryViewer()}
|
{hasSelectedStoryData && renderStoryViewer()}
|
||||||
{contents}
|
{contents}
|
||||||
</div>
|
</div>
|
||||||
</TitleBarContainer>
|
</TitleBarContainer>
|
||||||
|
|
|
@ -62,9 +62,9 @@ export type StoryDataType = {
|
||||||
|
|
||||||
export type SelectedStoryDataType = {
|
export type SelectedStoryDataType = {
|
||||||
currentIndex: number;
|
currentIndex: number;
|
||||||
|
messageId: string;
|
||||||
numStories: number;
|
numStories: number;
|
||||||
shouldShowDetailsModal: boolean;
|
shouldShowDetailsModal: boolean;
|
||||||
story: StoryDataType;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// State
|
// State
|
||||||
|
@ -631,9 +631,9 @@ function viewUserStories(
|
||||||
payload: {
|
payload: {
|
||||||
selectedStoryData: {
|
selectedStoryData: {
|
||||||
currentIndex,
|
currentIndex,
|
||||||
|
messageId: story.messageId,
|
||||||
numStories,
|
numStories,
|
||||||
shouldShowDetailsModal,
|
shouldShowDetailsModal,
|
||||||
story,
|
|
||||||
},
|
},
|
||||||
storyViewMode: hasUnread
|
storyViewMode: hasUnread
|
||||||
? StoryViewModeType.Unread
|
? StoryViewModeType.Unread
|
||||||
|
@ -699,9 +699,9 @@ const viewStory: ViewStoryActionCreatorType = ({
|
||||||
payload: {
|
payload: {
|
||||||
selectedStoryData: {
|
selectedStoryData: {
|
||||||
currentIndex,
|
currentIndex,
|
||||||
|
messageId: storyId,
|
||||||
numStories,
|
numStories,
|
||||||
shouldShowDetailsModal,
|
shouldShowDetailsModal,
|
||||||
story,
|
|
||||||
},
|
},
|
||||||
storyViewMode,
|
storyViewMode,
|
||||||
},
|
},
|
||||||
|
@ -722,9 +722,9 @@ const viewStory: ViewStoryActionCreatorType = ({
|
||||||
payload: {
|
payload: {
|
||||||
selectedStoryData: {
|
selectedStoryData: {
|
||||||
currentIndex: nextIndex,
|
currentIndex: nextIndex,
|
||||||
|
messageId: nextStory.messageId,
|
||||||
numStories,
|
numStories,
|
||||||
shouldShowDetailsModal: false,
|
shouldShowDetailsModal: false,
|
||||||
story: nextStory,
|
|
||||||
},
|
},
|
||||||
storyViewMode,
|
storyViewMode,
|
||||||
},
|
},
|
||||||
|
@ -742,9 +742,9 @@ const viewStory: ViewStoryActionCreatorType = ({
|
||||||
payload: {
|
payload: {
|
||||||
selectedStoryData: {
|
selectedStoryData: {
|
||||||
currentIndex: nextIndex,
|
currentIndex: nextIndex,
|
||||||
|
messageId: nextStory.messageId,
|
||||||
numStories,
|
numStories,
|
||||||
shouldShowDetailsModal: false,
|
shouldShowDetailsModal: false,
|
||||||
story: nextStory,
|
|
||||||
},
|
},
|
||||||
storyViewMode,
|
storyViewMode,
|
||||||
},
|
},
|
||||||
|
@ -771,9 +771,9 @@ const viewStory: ViewStoryActionCreatorType = ({
|
||||||
payload: {
|
payload: {
|
||||||
selectedStoryData: {
|
selectedStoryData: {
|
||||||
currentIndex: nextSelectedStoryData.currentIndex,
|
currentIndex: nextSelectedStoryData.currentIndex,
|
||||||
|
messageId: unreadStory.messageId,
|
||||||
numStories: nextSelectedStoryData.numStories,
|
numStories: nextSelectedStoryData.numStories,
|
||||||
shouldShowDetailsModal: false,
|
shouldShowDetailsModal: false,
|
||||||
story: unreadStory,
|
|
||||||
},
|
},
|
||||||
storyViewMode,
|
storyViewMode,
|
||||||
},
|
},
|
||||||
|
@ -832,9 +832,10 @@ const viewStory: ViewStoryActionCreatorType = ({
|
||||||
payload: {
|
payload: {
|
||||||
selectedStoryData: {
|
selectedStoryData: {
|
||||||
currentIndex: 0,
|
currentIndex: 0,
|
||||||
|
messageId:
|
||||||
|
nextSelectedStoryData.storiesByConversationId[0].messageId,
|
||||||
numStories: nextSelectedStoryData.numStories,
|
numStories: nextSelectedStoryData.numStories,
|
||||||
shouldShowDetailsModal: false,
|
shouldShowDetailsModal: false,
|
||||||
story: nextSelectedStoryData.storiesByConversationId[0],
|
|
||||||
},
|
},
|
||||||
storyViewMode,
|
storyViewMode,
|
||||||
},
|
},
|
||||||
|
@ -869,9 +870,10 @@ const viewStory: ViewStoryActionCreatorType = ({
|
||||||
payload: {
|
payload: {
|
||||||
selectedStoryData: {
|
selectedStoryData: {
|
||||||
currentIndex: 0,
|
currentIndex: 0,
|
||||||
|
messageId:
|
||||||
|
nextSelectedStoryData.storiesByConversationId[0].messageId,
|
||||||
numStories: nextSelectedStoryData.numStories,
|
numStories: nextSelectedStoryData.numStories,
|
||||||
shouldShowDetailsModal: false,
|
shouldShowDetailsModal: false,
|
||||||
story: nextSelectedStoryData.storiesByConversationId[0],
|
|
||||||
},
|
},
|
||||||
storyViewMode,
|
storyViewMode,
|
||||||
},
|
},
|
||||||
|
|
|
@ -40,6 +40,11 @@ export const shouldShowStoriesView = createSelector(
|
||||||
({ isShowingStoriesView }): boolean => isShowingStoriesView
|
({ isShowingStoriesView }): boolean => isShowingStoriesView
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const hasSelectedStoryData = createSelector(
|
||||||
|
getStoriesState,
|
||||||
|
({ selectedStoryData }): boolean => Boolean(selectedStoryData)
|
||||||
|
);
|
||||||
|
|
||||||
export const getSelectedStoryData = createSelector(
|
export const getSelectedStoryData = createSelector(
|
||||||
getStoriesState,
|
getStoriesState,
|
||||||
({ selectedStoryData }): SelectedStoryDataType | undefined =>
|
({ selectedStoryData }): SelectedStoryDataType | undefined =>
|
||||||
|
@ -370,3 +375,25 @@ export const getHasStoriesSelector = createSelector(
|
||||||
: HasStories.Read;
|
: HasStories.Read;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const getStoryByIdSelector = createSelector(
|
||||||
|
getStoriesState,
|
||||||
|
({ stories }) =>
|
||||||
|
(
|
||||||
|
conversationSelector: GetConversationByIdType,
|
||||||
|
messageId: string
|
||||||
|
):
|
||||||
|
| { conversationStory: ConversationStoryType; storyView: StoryViewType }
|
||||||
|
| undefined => {
|
||||||
|
const story = stories.find(item => item.messageId === messageId);
|
||||||
|
|
||||||
|
if (!story) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
conversationStory: getConversationStory(conversationSelector, story),
|
||||||
|
storyView: getStoryView(conversationSelector, story),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -25,7 +25,7 @@ import {
|
||||||
getMenuOptions,
|
getMenuOptions,
|
||||||
} from '../selectors/user';
|
} from '../selectors/user';
|
||||||
import {
|
import {
|
||||||
getSelectedStoryData,
|
hasSelectedStoryData,
|
||||||
shouldShowStoriesView,
|
shouldShowStoriesView,
|
||||||
} from '../selectors/stories';
|
} from '../selectors/stories';
|
||||||
import { getHideMenuBar } from '../selectors/items';
|
import { getHideMenuBar } from '../selectors/items';
|
||||||
|
@ -65,7 +65,7 @@ const mapStateToProps = (state: StateType) => {
|
||||||
<SmartStories />
|
<SmartStories />
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
),
|
),
|
||||||
selectedStoryData: getSelectedStoryData(state),
|
hasSelectedStoryData: hasSelectedStoryData(state),
|
||||||
renderStoryViewer: () => (
|
renderStoryViewer: () => (
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<SmartStoryViewer />
|
<SmartStoryViewer />
|
||||||
|
|
|
@ -20,10 +20,9 @@ import {
|
||||||
import { getIntl } from '../selectors/user';
|
import { getIntl } from '../selectors/user';
|
||||||
import { getPreferredBadgeSelector } from '../selectors/badges';
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
||||||
import {
|
import {
|
||||||
getConversationStory,
|
|
||||||
getSelectedStoryData,
|
getSelectedStoryData,
|
||||||
getStoryReplies,
|
getStoryReplies,
|
||||||
getStoryView,
|
getStoryByIdSelector,
|
||||||
} from '../selectors/stories';
|
} from '../selectors/stories';
|
||||||
import { renderEmojiPicker } from './renderEmojiPicker';
|
import { renderEmojiPicker } from './renderEmojiPicker';
|
||||||
import { strictAssert } from '../../util/assert';
|
import { strictAssert } from '../../util/assert';
|
||||||
|
@ -57,11 +56,18 @@ export function SmartStoryViewer(): JSX.Element | null {
|
||||||
getConversationSelector
|
getConversationSelector
|
||||||
);
|
);
|
||||||
|
|
||||||
const storyView = getStoryView(conversationSelector, selectedStoryData.story);
|
const getStoryById = useSelector(getStoryByIdSelector);
|
||||||
const conversationStory = getConversationStory(
|
|
||||||
|
const storyInfo = getStoryById(
|
||||||
conversationSelector,
|
conversationSelector,
|
||||||
selectedStoryData.story
|
selectedStoryData.messageId
|
||||||
);
|
);
|
||||||
|
strictAssert(
|
||||||
|
storyInfo,
|
||||||
|
'StoryViewer: selected story does not exist in stories'
|
||||||
|
);
|
||||||
|
const { conversationStory, storyView } = storyInfo;
|
||||||
|
|
||||||
const storyViewMode = useSelector<StateType, StoryViewModeType | undefined>(
|
const storyViewMode = useSelector<StateType, StoryViewModeType | undefined>(
|
||||||
state => state.stories.storyViewMode
|
state => state.stories.storyViewMode
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue