diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index 3b88ee14c..2bbab91f7 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -149,7 +149,7 @@ export default function App() { .catch(() => { setFetchError(true); }); - }, 5000); + }, 20000); // Clean up the timer on component unmount return () => { diff --git a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx index ae030e0b7..5852d6999 100644 --- a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx @@ -64,6 +64,7 @@ export default function Page({ const onEdgesChange = useFlowStore((state) => state.onEdgesChange); const setNodes = useFlowStore((state) => state.setNodes); const setEdges = useFlowStore((state) => state.setEdges); + const cleanFlow = useFlowStore((state) => state.cleanFlow); const deleteNode = useFlowStore((state) => state.deleteNode); const deleteEdge = useFlowStore((state) => state.deleteEdge); const undo = useFlowsManagerStore((state) => state.undo); @@ -170,6 +171,12 @@ export default function Page({ } }, [currentFlowId, reactFlowInstance]); + useEffect(() => { + return () => { + cleanFlow(); + } + }, []) + const onConnectMod = useCallback( (params: Connection) => { takeSnapshot(); @@ -210,26 +217,30 @@ export default function Page({ const onConnect = useCallback( (connection: Connection) => { - const newEdges = addEdge( - { - ...connection, - data: { - targetHandle: scapeJSONParse(connection.targetHandle!), - sourceHandle: scapeJSONParse(connection.sourceHandle!), + let newEdges:Edge[] = [] + setEdges((oldEdges) => { + newEdges = addEdge( + { + ...connection, + data: { + targetHandle: scapeJSONParse(connection.targetHandle!), + sourceHandle: scapeJSONParse(connection.sourceHandle!), + }, + style: { stroke: "#555" }, + className: + ((scapeJSONParse(connection.targetHandle!) as targetHandleType) + .type === "Text" + ? "stroke-foreground " + : "stroke-foreground ") + " stroke-connection", + animated: + (scapeJSONParse(connection.targetHandle!) as targetHandleType) + .type === "Text", }, - style: { stroke: "#555" }, - className: - ((scapeJSONParse(connection.targetHandle!) as targetHandleType) - .type === "Text" - ? "stroke-foreground " - : "stroke-foreground ") + " stroke-connection", - animated: - (scapeJSONParse(connection.targetHandle!) as targetHandleType) - .type === "Text", - }, - edges - ); - setEdges(newEdges); + oldEdges + ); + return newEdges; + + }) useFlowsManagerStore .getState() .autoSaveCurrentFlow( @@ -238,7 +249,7 @@ export default function Page({ reactFlowInstance?.getViewport() ?? { x: 0, y: 0, zoom: 1 } ); }, - [nodes, edges, setEdges, reactFlowInstance, addEdge] + [nodes, setEdges, reactFlowInstance, addEdge] ); const onDrop = useCallback( @@ -357,7 +368,7 @@ export default function Page({
{Object.keys(templates).length > 0 && - Object.keys(types).length > 0 ? ( + Object.keys(types).length > 0 ? (
((set, get) => ({ setLastCopiedSelection: (newSelection) => { set({ lastCopiedSelection: newSelection }); }, + cleanFlow: () => { + set({ + nodes: [], + edges: [], + flowState: undefined, + sseData: {}, + isBuilt: false, + }); + }, })); export default useFlowStore; diff --git a/src/frontend/src/types/zustand/flow/index.ts b/src/frontend/src/types/zustand/flow/index.ts index 9c331892f..50d2fd45b 100644 --- a/src/frontend/src/types/zustand/flow/index.ts +++ b/src/frontend/src/types/zustand/flow/index.ts @@ -49,4 +49,5 @@ export type FlowStoreType = { ) => void; isBuilt: boolean; setIsBuilt: (isBuilt: boolean) => void; + cleanFlow: () => void; };