signal-desktop/ts/components/CallParticipantCount.tsx

71 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-10-25 13:40:22 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import type { LocalizerType } from '../types/Util';
2024-02-22 21:19:50 +00:00
import { CallMode } from '../types/Calling';
2023-10-25 13:40:22 +00:00
export type PropsType = {
2024-02-22 21:19:50 +00:00
callMode: CallMode;
2023-10-25 13:40:22 +00:00
i18n: LocalizerType;
2024-02-22 21:19:50 +00:00
isAdhocJoinRequestPending?: boolean;
2023-10-25 13:40:22 +00:00
groupMemberCount?: number;
participantCount: number;
toggleParticipants: () => void;
};
export function CallParticipantCount({
2024-02-22 21:19:50 +00:00
callMode,
2023-10-25 13:40:22 +00:00
i18n,
2024-02-22 21:19:50 +00:00
isAdhocJoinRequestPending,
2023-10-25 13:40:22 +00:00
groupMemberCount,
participantCount,
toggleParticipants,
}: PropsType): JSX.Element {
2024-02-22 21:19:50 +00:00
const isToggleVisible =
Boolean(participantCount) || callMode === CallMode.Adhoc;
2023-10-25 13:40:22 +00:00
const count = participantCount || groupMemberCount || 1;
2024-02-22 21:19:50 +00:00
let innerText: string | undefined;
if (callMode === CallMode.Adhoc) {
if (isAdhocJoinRequestPending) {
innerText = i18n(
'icu:CallControls__InfoDisplay--adhoc-join-request-pending'
);
} else if (!participantCount) {
innerText = i18n('icu:CallControls__InfoDisplay--adhoc-call');
}
}
if (!innerText) {
innerText = i18n('icu:CallControls__InfoDisplay--participants', {
2024-02-29 23:07:50 +00:00
count,
2024-02-22 21:19:50 +00:00
});
}
2023-10-25 13:40:22 +00:00
// Call not started, can't click to show participants
2024-02-22 21:19:50 +00:00
if (!isToggleVisible) {
2023-10-25 13:40:22 +00:00
return (
<span
2024-03-04 18:03:11 +00:00
aria-label={i18n('icu:calling__participants--pluralized', {
2024-02-29 23:07:50 +00:00
people: count,
2023-10-25 13:40:22 +00:00
})}
className="CallControls__Status--InactiveCallParticipantCount"
>
{innerText}
</span>
);
}
return (
<button
2024-03-04 18:03:11 +00:00
aria-label={i18n('icu:calling__participants--pluralized', {
2024-02-29 23:07:50 +00:00
people: count,
2023-10-25 13:40:22 +00:00
})}
className="CallControls__Status--ParticipantCount"
onClick={toggleParticipants}
type="button"
>
{innerText}
</button>
);
}