()
| 59 | const logger = createLogger('CollaborativeWorkflow') |
| 60 | |
| 61 | export function useCollaborativeWorkflow() { |
| 62 | const queryClient = useQueryClient() |
| 63 | const undoRedo = useUndoRedo() |
| 64 | const isUndoRedoInProgress = useRef(false) |
| 65 | const lastDiffOperationId = useRef<string | null>(null) |
| 66 | |
| 67 | useEffect(() => { |
| 68 | const moveHandler = (e: any) => { |
| 69 | const { blockId, before, after } = e.detail || {} |
| 70 | if (!blockId || !before || !after) return |
| 71 | if (isUndoRedoInProgress.current) return |
| 72 | undoRedo.recordBatchMoveBlocks([{ blockId, before, after }]) |
| 73 | } |
| 74 | |
| 75 | const parentUpdateHandler = (e: any) => { |
| 76 | const { blockId, oldParentId, newParentId, oldPosition, newPosition, affectedEdges } = |
| 77 | e.detail || {} |
| 78 | if (!blockId) return |
| 79 | if (isUndoRedoInProgress.current) return |
| 80 | undoRedo.recordUpdateParent( |
| 81 | blockId, |
| 82 | oldParentId, |
| 83 | newParentId, |
| 84 | oldPosition, |
| 85 | newPosition, |
| 86 | affectedEdges |
| 87 | ) |
| 88 | } |
| 89 | |
| 90 | const diffOperationHandler = (e: any) => { |
| 91 | const { |
| 92 | type, |
| 93 | baselineSnapshot, |
| 94 | proposedState, |
| 95 | diffAnalysis, |
| 96 | beforeAccept, |
| 97 | afterAccept, |
| 98 | beforeReject, |
| 99 | afterReject, |
| 100 | } = e.detail || {} |
| 101 | // Don't record during undo/redo operations |
| 102 | if (isUndoRedoInProgress.current) return |
| 103 | |
| 104 | // Generate a unique ID for this diff operation to prevent duplicates |
| 105 | // Use block keys from the relevant states for each operation type |
| 106 | let stateForId |
| 107 | if (type === 'apply-diff') { |
| 108 | stateForId = proposedState |
| 109 | } else if (type === 'accept-diff') { |
| 110 | stateForId = afterAccept |
| 111 | } else if (type === 'reject-diff') { |
| 112 | stateForId = afterReject |
| 113 | } |
| 114 | |
| 115 | const blockKeys = stateForId?.blocks ? Object.keys(stateForId.blocks).sort().join(',') : '' |
| 116 | const operationId = `${type}-${blockKeys}` |
| 117 | |
| 118 | if (lastDiffOperationId.current === operationId) { |
no test coverage detected