Added debouncing on node and edge change to not make unnecessary saveFlows.
This commit is contained in:
parent
20f0e758a4
commit
f533ab43f9
1 changed files with 15 additions and 4 deletions
|
|
@ -695,13 +695,24 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveCurrentFlow(nodes: Node[], edges: Edge[], viewport: Viewport) {
|
const saveTimeoutId = useRef<NodeJS.Timeout | null>(null);
|
||||||
const currentFlow = flows.find((flow) => flow.id === tabId);
|
|
||||||
if (currentFlow) {
|
const saveCurrentFlow = (nodes: Node[], edges: Edge[], viewport: Viewport) => {
|
||||||
saveFlow({ ...currentFlow, data: { nodes, edges, viewport } }, true);
|
// Clear the previous timeout if it exists.
|
||||||
|
if (saveTimeoutId.current) {
|
||||||
|
clearTimeout(saveTimeoutId.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up a new timeout.
|
||||||
|
saveTimeoutId.current = setTimeout(() => {
|
||||||
|
const currentFlow = flows.find((flow: FlowType) => flow.id === tabId);
|
||||||
|
if (currentFlow) {
|
||||||
|
saveFlow({ ...currentFlow, data: { nodes, edges, viewport } }, true);
|
||||||
|
}
|
||||||
|
}, 300); // Delay of 300ms.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function saveFlow(flow?: FlowType, silent?: boolean) {
|
async function saveFlow(flow?: FlowType, silent?: boolean) {
|
||||||
let newFlow;
|
let newFlow;
|
||||||
if (!flow) {
|
if (!flow) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue