From 2035186cd290c40de7187c7095b5c7e1c9badd1f Mon Sep 17 00:00:00 2001 From: hjlarry Date: Thu, 11 Sep 2025 09:26:05 +0800 Subject: [PATCH] click avatar to follow user cursor position --- .../workflow/header/online-users.tsx | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/web/app/components/workflow/header/online-users.tsx b/web/app/components/workflow/header/online-users.tsx index d75bc4887f..a09dfaa979 100644 --- a/web/app/components/workflow/header/online-users.tsx +++ b/web/app/components/workflow/header/online-users.tsx @@ -1,5 +1,6 @@ 'use client' import { useEffect, useState } from 'react' +import { useReactFlow } from 'reactflow' import Avatar from '@/app/components/base/avatar' import { useCollaboration } from '../collaboration/hooks/use-collaboration' import { useStore } from '../store' @@ -49,13 +50,23 @@ const useAvatarUrls = (users: any[]) => { const OnlineUsers = () => { const appId = useStore(s => s.appId) - const { onlineUsers } = useCollaboration(appId) + const { onlineUsers, cursors } = useCollaboration(appId) const { userProfile } = useAppContext() + const reactFlow = useReactFlow() const [dropdownOpen, setDropdownOpen] = useState(false) const avatarUrls = useAvatarUrls(onlineUsers || []) const currentUserId = userProfile?.id + // Function to jump to user's cursor position + const jumpToUserCursor = (userId: string) => { + const cursor = cursors[userId] + if (!cursor) return + + // Convert world coordinates to center the view on the cursor + reactFlow.setCenter(cursor.x, cursor.y, { zoom: 1, duration: 800 }) + } + if (!onlineUsers || onlineUsers.length === 0) return null @@ -92,8 +103,12 @@ const OnlineUsers = () => { asChild >
!isCurrentUser && jumpToUserCursor(user.user_id)} > { return (
!isCurrentUser && jumpToUserCursor(user.user_id)} > - +
+ +
{displayName}