rm useCollaborativeCursors compoent

This commit is contained in:
hjlarry 2025-08-07 18:03:12 +08:00
parent ad8fd8fecc
commit d1a5db3310
3 changed files with 13 additions and 22 deletions

View File

@ -3,6 +3,7 @@ import {
useEffect,
useMemo,
useRef,
useState,
} from 'react'
import { useFeaturesStore } from '@/app/components/base/features/hooks'
import type { Features as FeaturesData } from '@/app/components/base/features/types'
@ -23,7 +24,6 @@ import {
useWorkflowStartRun,
} from '../hooks'
import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
import { useCollaborativeCursors } from '../hooks'
import { useCollaboration } from '@/app/components/workflow/collaboration'
import { collaborationManager } from '@/app/components/workflow/collaboration'
import { fetchWorkflowDraft } from '@/service/workflow'
@ -133,7 +133,17 @@ const WorkflowMain = ({
handleWorkflowStartRunInWorkflow,
} = useWorkflowStartRun()
const { cursors, myUserId } = useCollaborativeCursors(appId)
const { cursors, isConnected } = useCollaboration(appId)
const [myUserId, setMyUserId] = useState<string | null>(null)
useEffect(() => {
if (isConnected)
setMyUserId('current-user')
}, [isConnected])
const filteredCursors = Object.fromEntries(
Object.entries(cursors).filter(([userId]) => userId !== myUserId),
)
const { fetchInspectVars } = useSetWorkflowVarsWithValue({
flowId: appId,
@ -231,7 +241,7 @@ const WorkflowMain = ({
>
<WorkflowChildren />
</WorkflowWithInnerContext>
<UserCursors cursors={cursors} myUserId={myUserId} onlineUsers={onlineUsers} />
<UserCursors cursors={filteredCursors} myUserId={myUserId} onlineUsers={onlineUsers} />
</div>
)
}

View File

@ -8,4 +8,3 @@ export * from './use-workflow-refresh-draft'
export * from '../../workflow/hooks/use-fetch-workflow-inspect-vars'
export * from './use-inspect-vars-crud'
export * from './use-configs-map'
export * from './use-workflow-websocket'

View File

@ -1,18 +0,0 @@
import { useEffect, useState } from 'react'
import { useCollaboration } from '@/app/components/workflow/collaboration'
export function useCollaborativeCursors(appId: string) {
const { cursors, isConnected } = useCollaboration(appId)
const [myUserId, setMyUserId] = useState<string | null>(null)
useEffect(() => {
if (isConnected)
setMyUserId('current-user')
}, [isConnected])
const filteredCursors = Object.fromEntries(
Object.entries(cursors).filter(([userId]) => userId !== myUserId),
)
return { cursors: filteredCursors, myUserId }
}