refactor node context menu III, added zustand
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user