From 0984a60ca2ea960820d7813d480a7d6830139485 Mon Sep 17 00:00:00 2001 From: Emir Karabeg Date: Wed, 29 Jan 2025 13:56:16 -0800 Subject: [PATCH] Added state persistence before unload --- stores/workflow/workflow-registry.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/stores/workflow/workflow-registry.ts b/stores/workflow/workflow-registry.ts index 93584c6b14..2025a461a2 100644 --- a/stores/workflow/workflow-registry.ts +++ b/stores/workflow/workflow-registry.ts @@ -195,6 +195,20 @@ const initializeRegistry = () => { const workflows = JSON.parse(savedRegistry) useWorkflowRegistry.setState({ workflows }) } + + // Add event listeners for page unload + window.addEventListener('beforeunload', () => { + // Save current workflow state + const currentId = useWorkflowRegistry.getState().activeWorkflowId + if (currentId) { + const currentState = useWorkflowStore.getState() + localStorage.setItem(`workflow-${currentId}`, JSON.stringify({ + blocks: currentState.blocks, + edges: currentState.edges, + history: currentState.history + })) + } + }) } // Call this in your app's entry point