Skip to content

Commit

Permalink
refactor: add helper function for determining which views should be s…
Browse files Browse the repository at this point in the history
…crolled to

- The logical condition in the useEffect was somewhat hard to read
- Added a case statement to make the logic more explicit / readable
  • Loading branch information
Mike-Heneghan committed Feb 1, 2024
1 parent 997f699 commit cdc5118
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion editor.planx.uk/src/components/Feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,19 @@ const Feedback: React.FC = () => {

const feedbackComponentRef = useRef<HTMLDivElement | null>(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",
Expand Down

0 comments on commit cdc5118

Please sign in to comment.