From 97854348c6f8b10c54688256c51438e5b89a9f54 Mon Sep 17 00:00:00 2001 From: Akalanka Perera Date: Wed, 3 Apr 2024 15:50:53 +0530 Subject: [PATCH] Fix: reset workspace on unmount --- src/hooks/events/workspace-load.ts | 8 +++++++- src/store/reducers/editor/index.ts | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/hooks/events/workspace-load.ts b/src/hooks/events/workspace-load.ts index 2f2dab9..883fa5b 100644 --- a/src/hooks/events/workspace-load.ts +++ b/src/hooks/events/workspace-load.ts @@ -3,7 +3,7 @@ import { useSelector } from "react-redux"; import { panAndZoom } from "@/components/workspace/zoom"; import { dataAttributes, ids, selectors } from "@/constants"; import { store } from "@/store"; -import { initializeElements, initializeWorkspace, sync } from "@/store/reducers/editor"; +import { initializeElements, initializeWorkspace, resetWorkspace, sync } from "@/store/reducers/editor"; import { ISTKProps } from "@/types"; import { d3Extended } from "@/utils"; @@ -47,6 +47,12 @@ const useWorkspaceLoad = (props: ISTKProps) => { store.dispatch(initializeWorkspace()); } }, [dataSynced]); + + useEffect(() => { + return () => { + store.dispatch(resetWorkspace()); + }; + }, []); }; export default useWorkspaceLoad; diff --git a/src/store/reducers/editor/index.ts b/src/store/reducers/editor/index.ts index 9cd9572..75435d6 100644 --- a/src/store/reducers/editor/index.ts +++ b/src/store/reducers/editor/index.ts @@ -86,6 +86,10 @@ export const slice = createSlice({ initializeWorkspace: (state) => { state.initialized = true; }, + resetWorkspace: (state) => { + state.initialized = false; + state.dataSynced = false; + }, setCursor: (state, action) => { state.cursor = action.payload; }, @@ -252,6 +256,7 @@ export const slice = createSlice({ export const { initializeWorkspace, + resetWorkspace, setCursor, clearCursor, setLocation,