Update selectedStoryData whenever its story changes

This commit is contained in:
Josh Perez 2022-07-29 16:22:55 -04:00 committed by GitHub
parent 58aaf1d0e7
commit c3bb3b152e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 19 deletions

View file

@ -40,6 +40,11 @@ export const shouldShowStoriesView = createSelector(
({ isShowingStoriesView }): boolean => isShowingStoriesView
);
export const hasSelectedStoryData = createSelector(
getStoriesState,
({ selectedStoryData }): boolean => Boolean(selectedStoryData)
);
export const getSelectedStoryData = createSelector(
getStoriesState,
({ selectedStoryData }): SelectedStoryDataType | undefined =>
@ -370,3 +375,25 @@ export const getHasStoriesSelector = createSelector(
: 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),
};
}
);