'use client'
import React from 'react'
import { PresenceUser } from '@/hooks/use-brainstorm-socket'
function Cursor({ x, y, name, color }: { x: number; y: number; name: string; color: string }) {
return (
)
}
export function LiveCursors({ others }: { others: PresenceUser[] }) {
return (
{others.map((user) => {
if (!user.cursor) return null
return (
)
})}
)
}
export function useCursorTracking(
containerRef: React.RefObject,
moveCursor: (cursor: { x: number; y: number } | null) => void
) {
React.useEffect(() => {
const container = containerRef.current
if (!container) return
const handleMove = (e: MouseEvent) => {
const rect = container.getBoundingClientRect()
moveCursor({ x: e.clientX - rect.left, y: e.clientY - rect.top })
}
const handleLeave = () => {
moveCursor(null)
}
container.addEventListener('mousemove', handleMove)
container.addEventListener('mouseleave', handleLeave)
return () => {
container.removeEventListener('mousemove', handleMove)
container.removeEventListener('mouseleave', handleLeave)
}
}, [containerRef, moveCursor])
}
export function PresenceAvatars({ others }: { others: PresenceUser[] }) {
if (others.length === 0) return null
return (
{others.slice(0, 4).map((user) => {
const initial = (user.name || '?').charAt(0).toUpperCase()
return (
{initial}
)
})}
{others.length > 4 && (
+{others.length - 4}
)}
)
}