@@ -665,6 +665,64 @@ export function useCollaborativeWorkflow() {
665665 [ executeQueuedOperation , workflowStore ]
666666 )
667667
668+ const collaborativeAddEdge = useCallback (
669+ ( edge : Edge ) => {
670+ executeQueuedOperation ( 'add' , 'edge' , edge , ( ) => workflowStore . addEdge ( edge ) )
671+ } ,
672+ [ executeQueuedOperation , workflowStore ]
673+ )
674+
675+ const collaborativeRemoveEdge = useCallback (
676+ ( edgeId : string ) => {
677+ executeQueuedOperation ( 'remove' , 'edge' , { id : edgeId } , ( ) =>
678+ workflowStore . removeEdge ( edgeId )
679+ )
680+ } ,
681+ [ executeQueuedOperation , workflowStore ]
682+ )
683+
684+ const collaborativeSetSubblockValue = useCallback (
685+ ( blockId : string , subblockId : string , value : any ) => {
686+ if ( isApplyingRemoteChange . current ) return
687+
688+ if ( ! currentWorkflowId || activeWorkflowId !== currentWorkflowId ) {
689+ logger . debug ( 'Skipping subblock update - not in active workflow' , {
690+ currentWorkflowId,
691+ activeWorkflowId,
692+ blockId,
693+ subblockId,
694+ } )
695+ return
696+ }
697+
698+ // Generate operation ID for queue tracking
699+ const operationId = crypto . randomUUID ( )
700+
701+ // Add to queue for retry mechanism
702+ addToQueue ( {
703+ id : operationId ,
704+ operation : {
705+ operation : 'subblock-update' ,
706+ target : 'subblock' ,
707+ payload : { blockId, subblockId, value } ,
708+ } ,
709+ workflowId : activeWorkflowId || '' ,
710+ userId : session ?. user ?. id || 'unknown' ,
711+ } )
712+
713+ // Apply locally first (immediate UI feedback)
714+ subBlockStore . setValue ( blockId , subblockId , value )
715+ } ,
716+ [
717+ subBlockStore ,
718+ emitSubblockUpdate ,
719+ currentWorkflowId ,
720+ activeWorkflowId ,
721+ addToQueue ,
722+ session ?. user ?. id ,
723+ ]
724+ )
725+
668726 const collaborativeDuplicateBlock = useCallback (
669727 ( sourceId : string ) => {
670728 const sourceBlock = workflowStore . blocks [ sourceId ]
@@ -737,69 +795,17 @@ export function useCollaborativeWorkflow() {
737795 const subBlockValues = subBlockStore . workflowValues [ activeWorkflowId || '' ] ?. [ sourceId ]
738796 if ( subBlockValues && activeWorkflowId ) {
739797 Object . entries ( subBlockValues ) . forEach ( ( [ subblockId , value ] ) => {
740- subBlockStore . setValue ( newId , subblockId , value )
798+ collaborativeSetSubblockValue ( newId , subblockId , value )
741799 } )
742800 }
743801 } )
744802 } ,
745- [ executeQueuedOperation , workflowStore , subBlockStore , activeWorkflowId ]
746- )
747-
748- const collaborativeAddEdge = useCallback (
749- ( edge : Edge ) => {
750- executeQueuedOperation ( 'add' , 'edge' , edge , ( ) => workflowStore . addEdge ( edge ) )
751- } ,
752- [ executeQueuedOperation , workflowStore ]
753- )
754-
755- const collaborativeRemoveEdge = useCallback (
756- ( edgeId : string ) => {
757- executeQueuedOperation ( 'remove' , 'edge' , { id : edgeId } , ( ) =>
758- workflowStore . removeEdge ( edgeId )
759- )
760- } ,
761- [ executeQueuedOperation , workflowStore ]
762- )
763-
764- const collaborativeSetSubblockValue = useCallback (
765- ( blockId : string , subblockId : string , value : any ) => {
766- if ( isApplyingRemoteChange . current ) return
767-
768- if ( ! currentWorkflowId || activeWorkflowId !== currentWorkflowId ) {
769- logger . debug ( 'Skipping subblock update - not in active workflow' , {
770- currentWorkflowId,
771- activeWorkflowId,
772- blockId,
773- subblockId,
774- } )
775- return
776- }
777-
778- // Generate operation ID for queue tracking
779- const operationId = crypto . randomUUID ( )
780-
781- // Add to queue for retry mechanism
782- addToQueue ( {
783- id : operationId ,
784- operation : {
785- operation : 'subblock-update' ,
786- target : 'subblock' ,
787- payload : { blockId, subblockId, value } ,
788- } ,
789- workflowId : activeWorkflowId || '' ,
790- userId : session ?. user ?. id || 'unknown' ,
791- } )
792-
793- // Apply locally first (immediate UI feedback)
794- subBlockStore . setValue ( blockId , subblockId , value )
795- } ,
796803 [
804+ executeQueuedOperation ,
805+ workflowStore ,
797806 subBlockStore ,
798- emitSubblockUpdate ,
799- currentWorkflowId ,
800807 activeWorkflowId ,
801- addToQueue ,
802- session ?. user ?. id ,
808+ collaborativeSetSubblockValue ,
803809 ]
804810 )
805811
0 commit comments