@@ -17,7 +17,6 @@ import { usePages } from "@/features/pageSidebar/api/usePages";
1717import useYDocStore from "@/shared/model/ydocStore" ;
1818import { calculateBestHandles } from "@/features/canvas/model/calculateHandles" ;
1919import { createSocketIOProvider } from "@/shared/api/socketProvider" ;
20- import { initializeYText } from "@/shared/model/yjs" ;
2120import { useCollaborativeCursors } from "./useCollaborativeCursors" ;
2221import { getSortedNodes } from "./sortNodes" ;
2322
@@ -43,16 +42,51 @@ export const useCanvas = () => {
4342 const holdingNodeRef = useRef < string | null > ( null ) ;
4443
4544 useEffect ( ( ) => {
46- if ( ! pages ) return ;
47-
4845 const yTitleMap = ydoc . getMap ( "title" ) ;
4946 const yEmojiMap = ydoc . getMap ( "emoji" ) ;
5047
51- pages . forEach ( ( page ) => {
52- initializeYText ( yTitleMap , `title_${ page . id } ` , page . title ) ;
53- initializeYText ( yEmojiMap , `emoji_${ page . id } ` , page . emoji || "" ) ;
48+ const nodesMap = ydoc . getMap ( "nodes" ) ;
49+
50+ yTitleMap . observeDeep ( ( event ) => {
51+ if ( ! event [ 0 ] . path . length ) return ;
52+
53+ const pageId = event [ 0 ] . path [ 0 ] . toString ( ) . split ( "_" ) [ 1 ] ;
54+ const value = event [ 0 ] . target . toString ( ) ;
55+
56+ const existingNode = nodesMap . get ( pageId ) as YNode ;
57+
58+ const newNode : YNode = {
59+ id : pageId ,
60+ type : "note" ,
61+ data : { title : value , id : pageId , emoji : existingNode . data . emoji } ,
62+ position : existingNode . position ,
63+ selected : false ,
64+ isHolding : false ,
65+ } ;
66+
67+ nodesMap . set ( pageId , newNode ) ;
68+ } ) ;
69+
70+ yEmojiMap . observeDeep ( ( event ) => {
71+ if ( ! event [ 0 ] . path . length ) return ;
72+
73+ const pageId = event [ 0 ] . path [ 0 ] . toString ( ) . split ( "_" ) [ 1 ] ;
74+ const value = event [ 0 ] . target . toString ( ) ;
75+
76+ const existingNode = nodesMap . get ( pageId ) as YNode ;
77+
78+ const newNode : YNode = {
79+ id : pageId ,
80+ type : "note" ,
81+ data : { title : existingNode . data . title , id : pageId , emoji : value } ,
82+ position : existingNode . position ,
83+ selected : false ,
84+ isHolding : false ,
85+ } ;
86+
87+ nodesMap . set ( pageId , newNode ) ;
5488 } ) ;
55- } , [ pages ] ) ;
89+ } , [ ] ) ;
5690
5791 useEffect ( ( ) => {
5892 if ( ! ydoc ) return ;
0 commit comments