Skip to content

Commit 5d55fdd

Browse files
committed
improvement(presence): show presence for the same user in another tab, fix z-index of multiplayer cursor to fall behind panel,terminal,sidebar but above blocks, improved connection detection
1 parent b813bf7 commit 5d55fdd

File tree

3 files changed

+63
-98
lines changed

3 files changed

+63
-98
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/cursors/cursors.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { memo, useMemo } from 'react'
44
import { useViewport } from 'reactflow'
5-
import { useSession } from '@/lib/auth/auth-client'
65
import { getUserColor } from '@/lib/workspaces/colors'
76
import { usePreventZoom } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks'
87
import { useSocket } from '@/app/workspace/providers/socket-provider'
@@ -20,30 +19,31 @@ interface CursorRenderData {
2019
}
2120

2221
const CursorsComponent = () => {
23-
const { presenceUsers } = useSocket()
22+
const { presenceUsers, currentSocketId } = useSocket()
2423
const viewport = useViewport()
25-
const session = useSession()
26-
const currentUserId = session.data?.user?.id
2724
const preventZoomRef = usePreventZoom()
2825

2926
const cursors = useMemo<CursorRenderData[]>(() => {
3027
return presenceUsers
3128
.filter((user): user is typeof user & { cursor: CursorPoint } => Boolean(user.cursor))
32-
.filter((user) => user.userId !== currentUserId)
29+
.filter((user) => user.socketId !== currentSocketId)
3330
.map((user) => ({
3431
id: user.socketId,
3532
name: user.userName?.trim() || 'Collaborator',
3633
cursor: user.cursor,
3734
color: getUserColor(user.userId),
3835
}))
39-
}, [currentUserId, presenceUsers])
36+
}, [currentSocketId, presenceUsers])
4037

4138
if (!cursors.length) {
4239
return null
4340
}
4441

4542
return (
46-
<div ref={preventZoomRef} className='pointer-events-none absolute inset-0 z-30 select-none'>
43+
<div
44+
ref={preventZoomRef}
45+
className='pointer-events-none absolute inset-0 z-[5] select-none overflow-hidden'
46+
>
4747
{cursors.map(({ id, name, cursor, color }) => {
4848
const x = cursor.x * viewport.zoom + viewport.x
4949
const y = cursor.y * viewport.zoom + viewport.y

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/workflow-item/avatars/avatars.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { type CSSProperties, useMemo } from 'react'
44
import { Avatar, AvatarFallback, AvatarImage, Tooltip } from '@/components/emcn'
5-
import { useSession } from '@/lib/auth/auth-client'
65
import { getUserColor } from '@/lib/workspaces/colors'
76
import { useSocket } from '@/app/workspace/providers/socket-provider'
87
import { SIDEBAR_WIDTH } from '@/stores/constants'
@@ -81,9 +80,7 @@ function UserAvatar({ user, index }: UserAvatarProps) {
8180
* @returns Avatar stack for workflow presence
8281
*/
8382
export function Avatars({ workflowId }: AvatarsProps) {
84-
const { presenceUsers, currentWorkflowId } = useSocket()
85-
const { data: session } = useSession()
86-
const currentUserId = session?.user?.id
83+
const { presenceUsers, currentWorkflowId, currentSocketId } = useSocket()
8784
const sidebarWidth = useSidebarStore((state) => state.sidebarWidth)
8885

8986
/**
@@ -99,14 +96,14 @@ export function Avatars({ workflowId }: AvatarsProps) {
9996

10097
/**
10198
* Only show presence for the currently active workflow.
102-
* Filter out the current user from the list.
99+
* Filter out the current socket connection (allows same user's other tabs to appear).
103100
*/
104101
const workflowUsers = useMemo(() => {
105102
if (currentWorkflowId !== workflowId) {
106103
return []
107104
}
108-
return presenceUsers.filter((user) => user.userId !== currentUserId)
109-
}, [presenceUsers, currentWorkflowId, workflowId, currentUserId])
105+
return presenceUsers.filter((user) => user.socketId !== currentSocketId)
106+
}, [presenceUsers, currentWorkflowId, workflowId, currentSocketId])
110107

111108
/**
112109
* Calculate visible users and overflow count

0 commit comments

Comments
 (0)