From 77bf3a8669ee10f82db8563246e1df0f4211dcb1 Mon Sep 17 00:00:00 2001 From: Alvaro <110414366+alvaro-signal@users.noreply.github.com> Date: Thu, 22 Sep 2022 14:18:26 -0600 Subject: [PATCH] Don't scroll to the bottom of story replies --- ts/components/StoryViewsNRepliesModal.tsx | 9 ++++++--- ts/util/lint/exceptions.json | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ts/components/StoryViewsNRepliesModal.tsx b/ts/components/StoryViewsNRepliesModal.tsx index cc676bc68..7140af681 100644 --- a/ts/components/StoryViewsNRepliesModal.tsx +++ b/ts/components/StoryViewsNRepliesModal.tsx @@ -136,6 +136,7 @@ export const StoryViewsNRepliesModal = ({ }: PropsType): JSX.Element | null => { const containerElementRef = useRef(null); const inputApiRef = useRef(); + const shouldScrollToBottomRef = useRef(false); const [bottom, setBottom] = useState(null); const [messageBodyText, setMessageBodyText] = useState(''); const [showReactionPicker, setShowReactionPicker] = useState(false); @@ -164,14 +165,15 @@ export const StoryViewsNRepliesModal = ({ strategy: 'fixed', }); + let composerElement: JSX.Element | undefined; + useEffect(() => { - if (replies.length) { + if (replies.length && shouldScrollToBottomRef.current) { bottom?.scrollIntoView({ behavior: 'smooth' }); + shouldScrollToBottomRef.current = false; } }, [bottom, replies.length]); - let composerElement: JSX.Element | undefined; - if (canReply) { composerElement = ( <> @@ -204,6 +206,7 @@ export const StoryViewsNRepliesModal = ({ onPickEmoji={insertEmoji} onSubmit={(...args) => { inputApiRef.current?.reset(); + shouldScrollToBottomRef.current = true; onReply(...args); }} onTextTooLong={onTextTooLong} diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 661e8fabb..0c26b6c9c 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -8632,6 +8632,13 @@ "reasonCategory": "falseMatch", "updated": "2018-09-19T21:59:32.770Z" }, + { + "rule": "React-useRef", + "path": "ts/components/StoryViewsNRepliesModal.tsx", + "line": " const shouldScrollToBottomRef = useRef(false);", + "reasonCategory": "usageTrusted", + "updated": "2022-09-22T03:07:22.153Z" + }, { "rule": "React-useRef", "path": "sticker-creator/components/StickerFrame.js",