From cdc511884b8a1d99d5c65c0decc7b5b4c303deab Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Thu, 1 Feb 2024 15:32:45 +0000 Subject: [PATCH] refactor: add helper function for determining which views should be scrolled to - The logical condition in the useEffect was somewhat hard to read - Added a case statement to make the logic more explicit / readable --- editor.planx.uk/src/components/Feedback/index.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/editor.planx.uk/src/components/Feedback/index.tsx b/editor.planx.uk/src/components/Feedback/index.tsx index f5a1662296..a60cf9b7f9 100644 --- a/editor.planx.uk/src/components/Feedback/index.tsx +++ b/editor.planx.uk/src/components/Feedback/index.tsx @@ -100,8 +100,19 @@ const Feedback: React.FC = () => { const feedbackComponentRef = useRef(null); + const shouldScrollToView = () => { + switch (currentFeedbackView) { + case "banner": + return false; + case "thanks": + return false; + default: + return true; + } + }; + useEffect(() => { - if (currentFeedbackView !== "banner" && currentFeedbackView !== "thanks") { + if (shouldScrollToView()) { feedbackComponentRef.current?.scrollIntoView({ behavior: "smooth", block: "start",