From 2fb72b1d1ef6771d68159515c7f7cf835342ab0b Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 29 Jan 2024 14:46:38 -0300 Subject: [PATCH] added local storage of flow state to fake chat memory for refresh page --- .../src/components/newChatView/index.tsx | 1 + src/frontend/src/stores/flowStore.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/components/newChatView/index.tsx b/src/frontend/src/components/newChatView/index.tsx index ec2c0d66c..56e0ae38e 100644 --- a/src/frontend/src/components/newChatView/index.tsx +++ b/src/frontend/src/components/newChatView/index.tsx @@ -40,6 +40,7 @@ export default function newChatView(): JSX.Element { useEffect(() => { const chatOutputResponses: FlowPoolObjectType[] = []; outputIds.forEach((outputId) => { + console.log("rodou", flowPool[outputId]); if (outputId.includes("ChatOutput")) { if (flowPool[outputId] && flowPool[outputId].length > 0) { chatOutputResponses.push(...flowPool[outputId]); diff --git a/src/frontend/src/stores/flowStore.ts b/src/frontend/src/stores/flowStore.ts index f74bd5576..fb5831a07 100644 --- a/src/frontend/src/stores/flowStore.ts +++ b/src/frontend/src/stores/flowStore.ts @@ -45,12 +45,19 @@ const useFlowStore = create((set, get) => ({ set({ flowPool }); }, addDataToFlowPool: (data: any, nodeId: string) => { + const currentFlow = useFlowsManagerStore.getState().currentFlow; let newFlowPool = cloneDeep({ ...get().flowPool }); if (!newFlowPool[nodeId]) newFlowPool[nodeId] = [data]; else { newFlowPool[nodeId].push(data); } get().setFlowPool(newFlowPool); + if (currentFlow) { + window.sessionStorage.setItem( + `${currentFlow!.id}`, + JSON.stringify(newFlowPool) + ); + } }, CleanFlowPool: () => { get().setFlowPool({}); @@ -59,9 +66,15 @@ const useFlowStore = create((set, get) => ({ set({ isPending }); }, resetFlow: ({ nodes, edges, viewport }) => { + const currentFlow = useFlowsManagerStore.getState().currentFlow; + let flowPool = {}; + if (currentFlow) { + flowPool = JSON.parse( + window.sessionStorage.getItem(`${currentFlow!.id}`) ?? "{}" + ); + } let newEdges = cleanEdges(nodes, edges); const { inputs, outputs } = getInputsAndOutputs(nodes); - set({ nodes, edges: newEdges, @@ -69,6 +82,7 @@ const useFlowStore = create((set, get) => ({ inputs, outputs, hasIO: inputs.length > 0 && outputs.length > 0, + flowPool, }); get().reactFlowInstance!.setViewport(viewport); },