signal-desktop/ts/components/CallingParticipantsList.stories.tsx

122 lines
3.6 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-10-15 19:53:21 +00:00
import * as React from 'react';
2021-05-28 16:15:17 +00:00
import { sample } from 'lodash';
2020-10-15 19:53:21 +00:00
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
import type { PropsType } from './CallingParticipantsList';
import { CallingParticipantsList } from './CallingParticipantsList';
2021-05-28 16:15:17 +00:00
import { AvatarColors } from '../types/Colors';
import type { GroupCallRemoteParticipantType } from '../types/Calling';
2023-08-16 20:54:39 +00:00
import { generateAci } from '../types/ServiceId';
import { getDefaultConversationWithServiceId } from '../test-both/helpers/getDefaultConversation';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2020-10-15 19:53:21 +00:00
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
2020-11-17 15:07:53 +00:00
function createParticipant(
participantProps: Partial<GroupCallRemoteParticipantType>
): GroupCallRemoteParticipantType {
return {
aci: generateAci(),
demuxId: 2,
2020-11-17 15:07:53 +00:00
hasRemoteAudio: Boolean(participantProps.hasRemoteAudio),
hasRemoteVideo: Boolean(participantProps.hasRemoteVideo),
2023-12-06 21:52:29 +00:00
isHandRaised: Boolean(participantProps.isHandRaised),
2024-01-23 19:08:21 +00:00
mediaKeysReceived: Boolean(participantProps.mediaKeysReceived),
presenting: Boolean(participantProps.presenting),
sharingScreen: Boolean(participantProps.sharingScreen),
videoAspectRatio: 1.3,
2023-08-16 20:54:39 +00:00
...getDefaultConversationWithServiceId({
2024-07-11 19:44:09 +00:00
avatarUrl: participantProps.avatarUrl,
2021-05-28 16:15:17 +00:00
color: sample(AvatarColors),
isBlocked: Boolean(participantProps.isBlocked),
name: participantProps.name,
profileName: participantProps.title,
title: String(participantProps.title),
}),
2020-11-17 15:07:53 +00:00
};
}
2020-10-15 19:53:21 +00:00
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
i18n,
conversationId: 'fake-conversation-id',
2020-10-15 19:53:21 +00:00
onClose: action('on-close'),
2023-08-16 20:54:39 +00:00
ourServiceId: generateAci(),
2020-11-17 15:07:53 +00:00
participants: overrideProps.participants || [],
showContactModal: action('show-contact-modal'),
2020-10-15 19:53:21 +00:00
});
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/CallingParticipantsList',
} satisfies Meta<PropsType>;
2020-10-15 19:53:21 +00:00
2022-11-18 00:45:19 +00:00
export function NoOne(): JSX.Element {
2020-10-15 19:53:21 +00:00
const props = createProps();
return <CallingParticipantsList {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function SoloCall(): JSX.Element {
2020-11-17 15:07:53 +00:00
const props = createProps({
participants: [
createParticipant({
title: 'Bardock',
}),
],
});
return <CallingParticipantsList {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-11-17 15:07:53 +00:00
2022-11-18 00:45:19 +00:00
export function ManyParticipants(): JSX.Element {
2020-10-15 19:53:21 +00:00
const props = createProps({
participants: [
2020-11-17 15:07:53 +00:00
createParticipant({
2020-10-15 19:53:21 +00:00
title: 'Son Goku',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
hasRemoteAudio: true,
hasRemoteVideo: true,
presenting: true,
2020-11-20 19:39:50 +00:00
name: 'Rage Trunks',
2020-10-15 19:53:21 +00:00
title: 'Rage Trunks',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
hasRemoteAudio: true,
2020-10-15 19:53:21 +00:00
title: 'Prince Vegeta',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
hasRemoteAudio: true,
hasRemoteVideo: true,
2020-11-20 19:39:50 +00:00
name: 'Goku Black',
2020-10-15 19:53:21 +00:00
title: 'Goku Black',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
isHandRaised: true,
2020-10-15 19:53:21 +00:00
title: 'Supreme Kai Zamasu',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
hasRemoteAudio: false,
hasRemoteVideo: true,
isHandRaised: true,
title: 'Chi Chi',
}),
createParticipant({
title: 'Someone With A Really Long Name',
}),
2020-10-15 19:53:21 +00:00
],
});
return <CallingParticipantsList {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-11-20 17:19:53 +00:00
2022-11-18 00:45:19 +00:00
export function Overflow(): JSX.Element {
2020-11-20 17:19:53 +00:00
const props = createProps({
participants: Array(50)
.fill(null)
.map(() => createParticipant({ title: 'Kirby' })),
});
return <CallingParticipantsList {...props} />;
2022-11-18 00:45:19 +00:00
}