From bd7d1fec3c932188c9abf5d7a09bd70d3aa2f406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 14 Nov 2024 16:28:35 +0000 Subject: [PATCH] fix: External portals --- editor.planx.uk/src/hooks/useScrollOnPreviousURLMatch.ts | 8 +++++--- .../FlowEditor/components/Flow/components/Portal.tsx | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/editor.planx.uk/src/hooks/useScrollOnPreviousURLMatch.ts b/editor.planx.uk/src/hooks/useScrollOnPreviousURLMatch.ts index edc6a3d68d..c01391d67e 100644 --- a/editor.planx.uk/src/hooks/useScrollOnPreviousURLMatch.ts +++ b/editor.planx.uk/src/hooks/useScrollOnPreviousURLMatch.ts @@ -2,7 +2,9 @@ import { useTheme } from "@mui/material/styles"; import { useStore } from "pages/FlowEditor/lib/store"; import { useEffect, useRef } from "react"; -const useScrollOnPreviousURLMatch = (id: string) => { +const useScrollOnPreviousURLMatch = ( + urlMatcher: string, +) => { const previousURL = useStore((state) => state.previousURL); const ref = useRef(null); const theme = useTheme(); @@ -10,7 +12,7 @@ const useScrollOnPreviousURLMatch = (id: string) => { useEffect(() => { if (!ref.current) return; - const isReturningFromPortal = previousURL?.endsWith(id); + const isReturningFromPortal = previousURL?.endsWith(urlMatcher); if (!isReturningFromPortal) return; // Center node @@ -31,7 +33,7 @@ const useScrollOnPreviousURLMatch = (id: string) => { }; ref.current.animate(keyframes, animationOptions); - }, [previousURL, id, theme]); + }, [previousURL, urlMatcher, theme]); return ref; }; diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Flow/components/Portal.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Flow/components/Portal.tsx index 98df98c4a4..b750a47885 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Flow/components/Portal.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Flow/components/Portal.tsx @@ -18,7 +18,7 @@ import Question from "./Question"; const ExternalPortal: React.FC = (props) => { const [href, setHref] = useState("Loading..."); - const ref = useScrollOnPreviousURLMatch(props.id); + const ref = useScrollOnPreviousURLMatch(href); const addExternalPortal = useStore.getState().addExternalPortal;