refactor node context menu III, added zustand

This commit is contained in:
2025-11-11 01:25:59 +01:00
parent 8e630839a0
commit cd4963a4bd
7 changed files with 124 additions and 139 deletions

View File

@@ -1,6 +1,6 @@
import { Input, Modal } from "antd";
import type { NodeContext } from "./Graph";
import { useState } from "react";
import { graphContext, type NodeContext } from "./Graph";
import { useContext, useState } from "react";
export default function NodeRenameModal({
nodeContext,
@@ -15,14 +15,15 @@ export default function NodeRenameModal({
return;
}
const [nodeName, setSelectedNodeName] = useState(nodeContext.nodeName);
const graphContextValue = useContext(graphContext)!;
function renameNode() {
const node = nodeContext.graph.nodes.find(n => n.id === nodeContext.nodeId);
const node = graphContextValue.graph.nodes.find(n => n.id === nodeContext.nodeId);
if (!node) {
return;
}
node.label = nodeName;
nodeContext.setGraph(prev => ({ ...prev, nodes: nodeContext.graph.nodes }));
graphContextValue.setGraph(prev => ({ ...prev, nodes: graphContextValue.graph.nodes }));
openRenameModal(false);
}