Skip to content

Commit

Permalink
Fix: reset workspace on unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Apr 3, 2024
1 parent 0c601c1 commit 9785434
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/hooks/events/workspace-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -47,6 +47,12 @@ const useWorkspaceLoad = (props: ISTKProps) => {
store.dispatch(initializeWorkspace());
}
}, [dataSynced]);

useEffect(() => {
return () => {
store.dispatch(resetWorkspace());
};
}, []);
};

export default useWorkspaceLoad;
5 changes: 5 additions & 0 deletions src/store/reducers/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -252,6 +256,7 @@ export const slice = createSlice({

export const {
initializeWorkspace,
resetWorkspace,
setCursor,
clearCursor,
setLocation,
Expand Down

0 comments on commit 9785434

Please sign in to comment.