mirror of https://github.com/msgbyte/tailchat
feat: add group badge for current room participants
parent
80347f9c41
commit
d99e556c79
@ -0,0 +1,37 @@
|
|||||||
|
import { Avatar, Tooltip, UserAvatar, UserName } from '@capital/component';
|
||||||
|
import React, { useEffect } from 'react';
|
||||||
|
import { useRoomParticipants } from '../utils/useRoomParticipants';
|
||||||
|
|
||||||
|
export const LivekitPanelBadge: React.FC<{
|
||||||
|
groupId: string;
|
||||||
|
panelId: string;
|
||||||
|
}> = React.memo((props) => {
|
||||||
|
const roomName = `${props.groupId}#${props.panelId}`;
|
||||||
|
const { participants, fetchParticipants } = useRoomParticipants(roomName);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchParticipants();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Avatar.Group
|
||||||
|
maxCount={4}
|
||||||
|
maxPopoverTrigger="click"
|
||||||
|
style={{ verticalAlign: 'middle' }}
|
||||||
|
maxStyle={{ color: '#f56a00', backgroundColor: '#fde3cf' }}
|
||||||
|
>
|
||||||
|
{participants.map((info, i) => (
|
||||||
|
<Tooltip
|
||||||
|
key={`${info.sid}#${i}`}
|
||||||
|
title={<UserName userId={info.identity} />}
|
||||||
|
placement="top"
|
||||||
|
>
|
||||||
|
<UserAvatar userId={info.identity} size={24} />
|
||||||
|
</Tooltip>
|
||||||
|
))}
|
||||||
|
</Avatar.Group>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
LivekitPanelBadge.displayName = 'LivekitPanelBadge';
|
||||||
|
|
||||||
|
export default LivekitPanelBadge;
|
@ -0,0 +1,34 @@
|
|||||||
|
import { useAsyncFn, useEvent } from '@capital/common';
|
||||||
|
import { useMemo, useRef } from 'react';
|
||||||
|
import { request } from '../request';
|
||||||
|
|
||||||
|
export function useRoomParticipants(roomName: string) {
|
||||||
|
const [{ value: participants = [], loading }, _handleFetchParticipants] =
|
||||||
|
useAsyncFn(async () => {
|
||||||
|
const { data } = await request.post('roomMembers', {
|
||||||
|
roomName,
|
||||||
|
});
|
||||||
|
|
||||||
|
return data ?? [];
|
||||||
|
}, [roomName]);
|
||||||
|
|
||||||
|
const fetchParticipants = useEvent(_handleFetchParticipants);
|
||||||
|
|
||||||
|
const lockRef = useRef(false);
|
||||||
|
|
||||||
|
const isFirstLoading = useMemo(() => {
|
||||||
|
if (loading && lockRef.current === false) {
|
||||||
|
lockRef.current = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}, [loading]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
loading,
|
||||||
|
isFirstLoading,
|
||||||
|
participants,
|
||||||
|
fetchParticipants,
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue