Fixes going to oldest unread story when viewing
This commit is contained in:
parent
87a5ddc437
commit
ff87caf526
4 changed files with 30 additions and 32 deletions
|
@ -39,7 +39,6 @@ function getDefaultProps(): PropsType {
|
||||||
preferredReactionEmoji: ['❤️', '👍', '👎', '😂', '😮', '😢'],
|
preferredReactionEmoji: ['❤️', '👍', '👎', '😂', '😮', '😢'],
|
||||||
queueStoryDownload: action('queueStoryDownload'),
|
queueStoryDownload: action('queueStoryDownload'),
|
||||||
renderEmojiPicker: () => <div />,
|
renderEmojiPicker: () => <div />,
|
||||||
selectedStoryIndex: 0,
|
|
||||||
stories: [
|
stories: [
|
||||||
{
|
{
|
||||||
attachment: fakeAttachment({
|
attachment: fakeAttachment({
|
||||||
|
@ -109,24 +108,6 @@ story.add('Multi story', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
story.add('So many stories (start on story 4)', () => {
|
|
||||||
const sender = getDefaultConversation();
|
|
||||||
return (
|
|
||||||
<StoryViewer
|
|
||||||
{...getDefaultProps()}
|
|
||||||
selectedStoryIndex={5}
|
|
||||||
stories={Array(20).fill({
|
|
||||||
attachment: fakeAttachment({
|
|
||||||
url: '/fixtures/snow.jpg',
|
|
||||||
}),
|
|
||||||
messageId: '123',
|
|
||||||
sender,
|
|
||||||
timestamp: Date.now(),
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
story.add('Caption', () => (
|
story.add('Caption', () => (
|
||||||
<StoryViewer
|
<StoryViewer
|
||||||
{...getDefaultProps()}
|
{...getDefaultProps()}
|
||||||
|
|
|
@ -2,7 +2,13 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import FocusTrap from 'focus-trap-react';
|
import FocusTrap from 'focus-trap-react';
|
||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
import React, {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
import { useSpring, animated, to } from '@react-spring/web';
|
import { useSpring, animated, to } from '@react-spring/web';
|
||||||
import type { BodyRangeType, LocalizerType } from '../types/Util';
|
import type { BodyRangeType, LocalizerType } from '../types/Util';
|
||||||
import type { ConversationType } from '../state/ducks/conversations';
|
import type { ConversationType } from '../state/ducks/conversations';
|
||||||
|
@ -62,7 +68,6 @@ export type PropsType = {
|
||||||
recentEmojis?: Array<string>;
|
recentEmojis?: Array<string>;
|
||||||
renderEmojiPicker: (props: RenderEmojiPickerProps) => JSX.Element;
|
renderEmojiPicker: (props: RenderEmojiPickerProps) => JSX.Element;
|
||||||
replyState?: ReplyStateType;
|
replyState?: ReplyStateType;
|
||||||
selectedStoryIndex: number;
|
|
||||||
skinTone?: number;
|
skinTone?: number;
|
||||||
stories: Array<StoryViewType>;
|
stories: Array<StoryViewType>;
|
||||||
views?: Array<string>;
|
views?: Array<string>;
|
||||||
|
@ -94,13 +99,11 @@ export const StoryViewer = ({
|
||||||
recentEmojis,
|
recentEmojis,
|
||||||
renderEmojiPicker,
|
renderEmojiPicker,
|
||||||
replyState,
|
replyState,
|
||||||
selectedStoryIndex,
|
|
||||||
skinTone,
|
skinTone,
|
||||||
stories,
|
stories,
|
||||||
views,
|
views,
|
||||||
}: PropsType): JSX.Element => {
|
}: PropsType): JSX.Element => {
|
||||||
const [currentStoryIndex, setCurrentStoryIndex] =
|
const [currentStoryIndex, setCurrentStoryIndex] = useState(0);
|
||||||
useState(selectedStoryIndex);
|
|
||||||
const [storyDuration, setStoryDuration] = useState<number | undefined>();
|
const [storyDuration, setStoryDuration] = useState<number | undefined>();
|
||||||
const [isShowingContextMenu, setIsShowingContextMenu] = useState(false);
|
const [isShowingContextMenu, setIsShowingContextMenu] = useState(false);
|
||||||
const [hasConfirmHideStory, setHasConfirmHideStory] = useState(false);
|
const [hasConfirmHideStory, setHasConfirmHideStory] = useState(false);
|
||||||
|
@ -155,12 +158,22 @@ export const StoryViewer = ({
|
||||||
setHasExpandedCaption(false);
|
setHasExpandedCaption(false);
|
||||||
}, [messageId]);
|
}, [messageId]);
|
||||||
|
|
||||||
// In case we want to change the story we're viewing from 0 -> N
|
// These exist to change currentStoryIndex to the oldest unread story a user
|
||||||
|
// has, or set to 0 whenever conversationId changes.
|
||||||
|
// We use a ref so that we only depend on conversationId changing, since
|
||||||
|
// the stories Array will change once we mark as story as viewed.
|
||||||
|
const storiesRef = useRef(stories);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedStoryIndex) {
|
const unreadStoryIndex = storiesRef.current.findIndex(
|
||||||
setCurrentStoryIndex(selectedStoryIndex);
|
story => story.isUnread
|
||||||
}
|
);
|
||||||
}, [selectedStoryIndex]);
|
setCurrentStoryIndex(unreadStoryIndex < 0 ? 0 : unreadStoryIndex);
|
||||||
|
}, [conversationId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
storiesRef.current = stories;
|
||||||
|
}, [stories]);
|
||||||
|
|
||||||
// Either we show the next story in the current user's stories or we ask
|
// Either we show the next story in the current user's stories or we ask
|
||||||
// for the next user's stories.
|
// for the next user's stories.
|
||||||
|
|
|
@ -55,8 +55,6 @@ export function SmartStoryViewer({
|
||||||
>(getStoriesSelector);
|
>(getStoriesSelector);
|
||||||
|
|
||||||
const { group, stories } = getStoriesByConversationId(conversationId);
|
const { group, stories } = getStoriesByConversationId(conversationId);
|
||||||
const unreadStoryIndex = stories.findIndex(story => story.isUnread);
|
|
||||||
const selectedStoryIndex = unreadStoryIndex > 0 ? unreadStoryIndex : 0;
|
|
||||||
|
|
||||||
const recentEmojis = useRecentEmojis();
|
const recentEmojis = useRecentEmojis();
|
||||||
const skinTone = useSelector<StateType, number>(getEmojiSkinTone);
|
const skinTone = useSelector<StateType, number>(getEmojiSkinTone);
|
||||||
|
@ -96,7 +94,6 @@ export function SmartStoryViewer({
|
||||||
recentEmojis={recentEmojis}
|
recentEmojis={recentEmojis}
|
||||||
renderEmojiPicker={renderEmojiPicker}
|
renderEmojiPicker={renderEmojiPicker}
|
||||||
replyState={replyState}
|
replyState={replyState}
|
||||||
selectedStoryIndex={selectedStoryIndex}
|
|
||||||
stories={stories}
|
stories={stories}
|
||||||
skinTone={skinTone}
|
skinTone={skinTone}
|
||||||
{...storiesActions}
|
{...storiesActions}
|
||||||
|
|
|
@ -7706,6 +7706,13 @@
|
||||||
"reasonCategory": "usageTrusted",
|
"reasonCategory": "usageTrusted",
|
||||||
"updated": "2022-04-29T23:54:21.656Z"
|
"updated": "2022-04-29T23:54:21.656Z"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"rule": "React-useRef",
|
||||||
|
"path": "ts/components/StoryViewer.tsx",
|
||||||
|
"line": " const storiesRef = useRef(stories);",
|
||||||
|
"reasonCategory": "usageTrusted",
|
||||||
|
"updated": "2022-04-30T00:44:47.213Z"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"rule": "React-useRef",
|
"rule": "React-useRef",
|
||||||
"path": "ts/components/StoryViewsNRepliesModal.tsx",
|
"path": "ts/components/StoryViewsNRepliesModal.tsx",
|
||||||
|
|
Loading…
Reference in a new issue