feat(flowsContext.tsx): add nodesOnFlow and setNodesOnFlow functions to FlowsContext to track changes in nodes on the flow
fix(PageComponent/index.tsx): update onNodesChangeMod function to only trigger when there are changes in the nodes on the flow and update nodesOnFlow state in FlowsContext feat(tabs/index.ts): add nodesOnFlow and setNodesOnFlow functions to FlowsContextType to track changes in nodes on the flow
This commit is contained in:
parent
cd1a290057
commit
8714ecfada
3 changed files with 32 additions and 13 deletions
|
|
@ -92,6 +92,8 @@ const FlowsContextInitialValue: FlowsContextType = {
|
||||||
saveComponent: async (component: NodeDataType, override: boolean) => "",
|
saveComponent: async (component: NodeDataType, override: boolean) => "",
|
||||||
deleteComponent: (key: string) => {},
|
deleteComponent: (key: string) => {},
|
||||||
version: "",
|
version: "",
|
||||||
|
nodesOnFlow: "",
|
||||||
|
setNodesOnFlow: (nodes: string) => "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FlowsContext = createContext<FlowsContextType>(
|
export const FlowsContext = createContext<FlowsContextType>(
|
||||||
|
|
@ -106,6 +108,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
const [tabId, setTabId] = useState("");
|
const [tabId, setTabId] = useState("");
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [nodesOnFlow, setNodesOnFlow] = useState("");
|
||||||
|
|
||||||
const [flows, setFlows] = useState<Array<FlowType>>([]);
|
const [flows, setFlows] = useState<Array<FlowType>>([]);
|
||||||
const [id, setId] = useState(uid());
|
const [id, setId] = useState(uid());
|
||||||
|
|
@ -666,6 +669,8 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(tabsState);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
|
|
@ -730,6 +735,8 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
isLoading,
|
isLoading,
|
||||||
saveComponent,
|
saveComponent,
|
||||||
deleteComponent,
|
deleteComponent,
|
||||||
|
nodesOnFlow,
|
||||||
|
setNodesOnFlow,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ export default function Page({
|
||||||
const reactFlowWrapper = useRef<HTMLDivElement>(null);
|
const reactFlowWrapper = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const { takeSnapshot } = useContext(undoRedoContext);
|
const { takeSnapshot } = useContext(undoRedoContext);
|
||||||
|
const { nodesOnFlow, setNodesOnFlow } = useContext(FlowsContext);
|
||||||
|
|
||||||
const position = useRef({ x: 0, y: 0 });
|
const position = useRef({ x: 0, y: 0 });
|
||||||
const [lastSelection, setLastSelection] =
|
const [lastSelection, setLastSelection] =
|
||||||
|
|
@ -219,7 +220,7 @@ export default function Page({
|
||||||
...prev,
|
...prev,
|
||||||
[tabId]: {
|
[tabId]: {
|
||||||
...prev[tabId],
|
...prev[tabId],
|
||||||
isPending: true,
|
isPending: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
@ -229,21 +230,30 @@ export default function Page({
|
||||||
|
|
||||||
const onNodesChangeMod = useCallback(
|
const onNodesChangeMod = useCallback(
|
||||||
(change: NodeChange[]) => {
|
(change: NodeChange[]) => {
|
||||||
onNodesChange(change);
|
const changeString = JSON.stringify(change);
|
||||||
//@ts-ignore
|
|
||||||
setTabsState((prev: FlowsState) => {
|
if (changeString !== nodesOnFlow) {
|
||||||
return {
|
onNodesChange(change);
|
||||||
...prev,
|
updateNodeFlow(changeString);
|
||||||
[tabId]: {
|
//@ts-ignore
|
||||||
...prev[tabId],
|
setTabsState((prev: FlowsState) => {
|
||||||
isPending: true,
|
return {
|
||||||
},
|
...prev,
|
||||||
};
|
[tabId]: {
|
||||||
});
|
...prev[tabId],
|
||||||
|
isPending: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[onNodesChange, setTabsState, tabId]
|
[onNodesChange, setTabsState, tabId, updateNodeFlow]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function updateNodeFlow(changeString: string) {
|
||||||
|
setNodesOnFlow(changeString);
|
||||||
|
}
|
||||||
|
|
||||||
const onConnect = useCallback(
|
const onConnect = useCallback(
|
||||||
(params: Connection) => {
|
(params: Connection) => {
|
||||||
takeSnapshot();
|
takeSnapshot();
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@ export type FlowsContextType = {
|
||||||
) => Promise<String | undefined>;
|
) => Promise<String | undefined>;
|
||||||
deleteComponent: (key: string) => void;
|
deleteComponent: (key: string) => void;
|
||||||
version: string;
|
version: string;
|
||||||
|
nodesOnFlow: string;
|
||||||
|
setNodesOnFlow: (nodes: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FlowsState = {
|
export type FlowsState = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue