From d1a5db3310d113e28e3d00db068614a1d1f413f6 Mon Sep 17 00:00:00 2001 From: hjlarry Date: Thu, 7 Aug 2025 18:03:12 +0800 Subject: [PATCH] rm useCollaborativeCursors compoent --- .../workflow-app/components/workflow-main.tsx | 16 +++++++++++++--- web/app/components/workflow-app/hooks/index.ts | 1 - .../hooks/use-workflow-websocket.ts | 18 ------------------ 3 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 web/app/components/workflow-app/hooks/use-workflow-websocket.ts diff --git a/web/app/components/workflow-app/components/workflow-main.tsx b/web/app/components/workflow-app/components/workflow-main.tsx index 694636af91..f7b9264384 100644 --- a/web/app/components/workflow-app/components/workflow-main.tsx +++ b/web/app/components/workflow-app/components/workflow-main.tsx @@ -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(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 = ({ > - + ) } diff --git a/web/app/components/workflow-app/hooks/index.ts b/web/app/components/workflow-app/hooks/index.ts index 99acd3e2c3..9e4f94965b 100644 --- a/web/app/components/workflow-app/hooks/index.ts +++ b/web/app/components/workflow-app/hooks/index.ts @@ -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' diff --git a/web/app/components/workflow-app/hooks/use-workflow-websocket.ts b/web/app/components/workflow-app/hooks/use-workflow-websocket.ts deleted file mode 100644 index 22f762c3c9..0000000000 --- a/web/app/components/workflow-app/hooks/use-workflow-websocket.ts +++ /dev/null @@ -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(null) - - useEffect(() => { - if (isConnected) - setMyUserId('current-user') - }, [isConnected]) - - const filteredCursors = Object.fromEntries( - Object.entries(cursors).filter(([userId]) => userId !== myUserId), - ) - - return { cursors: filteredCursors, myUserId } -}