55
66import type { NodeModel } from "@defs/Node" ;
77
8- import { useUnsavedChangesContext } from "@contexts/unsavedChanges " ;
8+ import { useNodeSystemContext } from "@contexts/nodeSystem " ;
99
1010import { DynamicIcon } from "@components/commons/DynamicIcon" ;
1111import { Glass } from "@components/commons/Glass" ;
@@ -24,9 +24,7 @@ export function Node({
2424 showCanvas ?: boolean ;
2525 forcedActive ?: boolean ;
2626} ) {
27- const {
28- setUnsavedChanges,
29- } = useUnsavedChangesContext ( ) ! ;
27+ const { updateNode } = useNodeSystemContext ( ) ! ;
3028
3129 const [ active , setActive ] = useState ( false ) ;
3230 const [ baseType , setBaseType ] = useState < string > ( node . baseType || "text" ) ;
@@ -39,8 +37,13 @@ export function Node({
3937 const switchBaseType = useCallback ( ( type : string ) => {
4038 node . baseType = type ;
4139 setBaseType ( type ) ;
42- setUnsavedChanges ( true ) ;
43- } , [ setUnsavedChanges , node ] ) ;
40+ updateNode ( node . id ! , node ) ;
41+ } , [ updateNode , node ] ) ;
42+
43+ const changeValue = useCallback ( ( value : string ) => {
44+ node . value = value ;
45+ updateNode ( node . id ! , node ) ;
46+ } , [ updateNode , node ] ) ;
4447
4548 return ( < >
4649 < div className = "node-wrapper" >
@@ -73,7 +76,7 @@ export function Node({
7376 < Glass
7477 className = { [
7578 "node-context" ,
76- node . context . length > 20 ? "left " : "" ,
79+ node . context . length > 20 ? "side " : "" ,
7780 ] . join ( " " ) }
7881 >
7982 {
@@ -129,10 +132,7 @@ export function Node({
129132 < Input
130133 placeholder = "Base Node Value"
131134 defaultValue = { node . value || "" }
132- onChange = { ( event ) => {
133- node . value = event . target . value ;
134- setUnsavedChanges ( true ) ;
135- } }
135+ onChange = { ( e ) => changeValue ( e . target . value ) }
136136 />
137137 </ div >
138138 </ > ) }
0 commit comments