import { useUserFields } from "@tensamin/identity/context"; import { useCall, getRoom } from "../store"; import { useEffect, useState } from "react"; import { useStorage } from "@tensamin/storage/context"; import { Avatar, AvatarFallback, AvatarImage, Tooltip, TooltipContent, TooltipTrigger, } from "@methanium/ui"; const USER_FIELDS = ["Avatar", "Display"] as const; function ParticipantAvatar({ userId, portalContainer, }: { userId: number; portalContainer?: HTMLElement; }) { const { data: user } = useUserFields(userId, USER_FIELDS); if (!user) return null; return (
{user.Display.slice(0, 2).toUpperCase()} } /> {user.Display}
); } export default function TopBar() { const { load } = useStorage(); const room = getRoom(); const screenRef = useCall((state) => state.screenRef); const [portalContainer, setPortalContainer] = useState(); useEffect(() => { setPortalContainer(screenRef?.current ?? undefined); }, [screenRef]); const userIds = Array.from( room.remoteParticipants.values(), (participant) => { const participantId = Number(participant.identity); return Number.isInteger(participantId) && participantId > 0 ? participantId : null; }, ).filter((participantId): participantId is number => participantId != null); const [ownId, setOwnId] = useState(); useEffect(() => { void load("user_id").then(setOwnId); }, [load]); const participantIds = ownId === undefined ? userIds : [ownId, ...userIds]; return (
{participantIds.map((userId) => ( ))}
); }