client/packages/call/src/components/top.tsx
Alois 930663d495
Some checks failed
/ build-desktop (linux) (push) Failing after 3m58s
/ build-web (push) Failing after 4m13s
/ build-mobile (push) Failing after 6m34s
/ release (push) Has been skipped
(feat): migrate ttp to mtp
(wip): crypto migration
2026-07-05 01:43:06 +02:00

97 lines
2.6 KiB
TypeScript

import { useUser, type User } from "@tensamin/user/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 "@tensamin/ui";
export default function TopBar() {
const { get } = useUser();
const { load } = useStorage();
const room = getRoom();
const screenRef = useCall((state) => state.screenRef);
const [portalContainer, setPortalContainer] = useState<HTMLElement>();
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 userIdsKey = userIds.join(",");
const [users, setUsers] = useState<User[]>([]);
useEffect(() => {
let active = true;
const ids = userIdsKey === "" ? [] : userIdsKey.split(",").map(Number);
void Promise.all(ids.map((id) => get(id)))
.then(async (users) => {
if (!active) {
return;
}
const ownId = await load("user_id");
const ownUser = await get(ownId);
setUsers([ownUser, ...users]);
})
.catch(async () => {
if (!active) {
return;
}
const ownId = await load("user_id");
const ownUser = await get(ownId);
setUsers([ownUser]);
});
return () => {
active = false;
};
}, [get, userIdsKey, load]);
return (
<div className="w-full flex justify-between h-12">
<div className="flex gap-1 m-3 ml-7">
{users.map((user) => (
<div key={user.UserId} className="-ml-4">
<Tooltip>
<TooltipTrigger
render={
<Avatar className="size-7">
<AvatarImage src={user.Avatar} />
<AvatarFallback className="text-xs">
{user.Display.slice(0, 2).toUpperCase()}
</AvatarFallback>
</Avatar>
}
/>
<TooltipContent
side="bottom"
portalProps={{ container: portalContainer }}
>
{user.Display}
</TooltipContent>
</Tooltip>
</div>
))}
</div>
</div>
);
}