// Copyright 2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only /* eslint-disable react/no-array-index-key */ import React, { useContext } from 'react'; import { createPortal } from 'react-dom'; import FocusTrap from 'focus-trap-react'; import classNames from 'classnames'; import { Avatar, AvatarSize } from './Avatar'; import { ContactName } from './conversation/ContactName'; import { InContactsIcon } from './InContactsIcon'; import type { LocalizerType } from '../types/Util'; import type { ServiceIdString } from '../types/ServiceId'; import { sortByTitle } from '../util/sortByTitle'; import type { ConversationType } from '../state/ducks/conversations'; import { isInSystemContacts } from '../util/isInSystemContacts'; import { ModalContainerContext } from './ModalHost'; type ParticipantType = ConversationType & { hasRemoteAudio?: boolean; hasRemoteVideo?: boolean; isHandRaised?: boolean; presenting?: boolean; }; export type PropsType = { readonly conversationId: string; readonly i18n: LocalizerType; readonly onClose: () => void; readonly ourServiceId: ServiceIdString | undefined; readonly participants: Array; readonly showContactModal: ( contactId: string, conversationId?: string ) => void; }; export const CallingParticipantsList = React.memo( function CallingParticipantsListInner({ conversationId, i18n, onClose, ourServiceId, participants, showContactModal, }: PropsType) { const [root, setRoot] = React.useState(null); const modalContainer = useContext(ModalContainerContext) ?? document.body; const sortedParticipants = React.useMemo>( () => sortByTitle(participants), [participants] ); React.useEffect(() => { const div = document.createElement('div'); modalContainer.appendChild(div); setRoot(div); return () => { modalContainer.removeChild(div); setRoot(null); }; }, [modalContainer]); const handleCancel = React.useCallback( (e: React.MouseEvent) => { if (e.target === e.currentTarget) { onClose(); } }, [onClose] ); if (!root) { return null; } return createPortal(
{participants.length ? i18n('icu:calling__in-this-call', { people: participants.length, }) : i18n('icu:calling__in-this-call--zero')}
{sortedParticipants.map( (participant: ParticipantType, index: number) => ( ) )}
, root ); } );