signal-desktop/ts/components/IncomingCallBar.tsx

164 lines
4.3 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-06-04 18:16:19 +00:00
import React from 'react';
import { Avatar } from './Avatar';
import { Tooltip } from './Tooltip';
import { Theme } from '../util/theme';
2020-06-04 18:16:19 +00:00
import { ContactName } from './conversation/ContactName';
import { LocalizerType } from '../types/Util';
import { ColorType } from '../types/Colors';
import { AcceptCallType, DeclineCallType } from '../state/ducks/calling';
2020-06-04 18:16:19 +00:00
export type PropsType = {
acceptCall: (_: AcceptCallType) => void;
declineCall: (_: DeclineCallType) => void;
i18n: LocalizerType;
call: {
isVideoCall: boolean;
};
conversation: {
id: string;
avatarPath?: string;
color?: ColorType;
title: string;
name?: string;
phoneNumber?: string;
profileName?: string;
};
2020-06-04 18:16:19 +00:00
};
type CallButtonProps = {
classSuffix: string;
tabIndex: number;
tooltipContent: string;
onClick: () => void;
};
const CallButton = ({
classSuffix,
onClick,
tabIndex,
tooltipContent,
}: CallButtonProps): JSX.Element => {
return (
<Tooltip content={tooltipContent} theme={Theme.Dark}>
2020-11-19 18:11:35 +00:00
<button
aria-label={tooltipContent}
2020-11-19 18:11:35 +00:00
className={`module-incoming-call__button module-incoming-call__button--${classSuffix}`}
onClick={onClick}
tabIndex={tabIndex}
type="button"
2020-06-04 18:16:19 +00:00
>
<div />
2020-11-19 18:11:35 +00:00
</button>
</Tooltip>
2020-06-04 18:16:19 +00:00
);
};
export const IncomingCallBar = ({
acceptCall,
declineCall,
i18n,
call,
conversation,
2020-06-04 18:16:19 +00:00
}: PropsType): JSX.Element | null => {
const { isVideoCall } = call;
2020-06-04 18:16:19 +00:00
const {
id: conversationId,
2020-06-04 18:16:19 +00:00
avatarPath,
2020-07-24 01:35:32 +00:00
color,
title,
2020-06-04 18:16:19 +00:00
name,
phoneNumber,
profileName,
} = conversation;
2020-06-04 18:16:19 +00:00
return (
<div className="module-incoming-call">
<div className="module-incoming-call__contact">
<div className="module-incoming-call__contact--avatar">
<Avatar
avatarPath={avatarPath}
2020-07-24 01:35:32 +00:00
color={color || 'ultramarine'}
2020-06-04 18:16:19 +00:00
noteToSelf={false}
conversationType="direct"
i18n={i18n}
name={name}
phoneNumber={phoneNumber}
profileName={profileName}
2020-07-24 01:35:32 +00:00
title={title}
2020-06-04 18:16:19 +00:00
size={52}
/>
</div>
<div className="module-incoming-call__contact--name">
<div className="module-incoming-call__contact--name-header">
<ContactName
name={name}
2020-07-24 01:35:32 +00:00
phoneNumber={phoneNumber}
2020-06-04 18:16:19 +00:00
profileName={profileName}
2020-07-24 01:35:32 +00:00
title={title}
i18n={i18n}
2020-06-04 18:16:19 +00:00
/>
</div>
<div
dir="auto"
className="module-incoming-call__contact--message-text"
>
{i18n(isVideoCall ? 'incomingVideoCall' : 'incomingAudioCall')}
2020-06-04 18:16:19 +00:00
</div>
</div>
</div>
<div className="module-incoming-call__actions">
{isVideoCall ? (
2020-06-04 18:16:19 +00:00
<>
<CallButton
classSuffix="decline"
onClick={() => {
declineCall({ conversationId });
2020-06-04 18:16:19 +00:00
}}
tabIndex={0}
tooltipContent={i18n('declineCall')}
/>
<CallButton
classSuffix="accept-video-as-audio"
onClick={() => {
acceptCall({ conversationId, asVideoCall: false });
2020-06-04 18:16:19 +00:00
}}
tabIndex={0}
tooltipContent={i18n('acceptCallWithoutVideo')}
/>
<CallButton
classSuffix="accept-video"
onClick={() => {
acceptCall({ conversationId, asVideoCall: true });
2020-06-04 18:16:19 +00:00
}}
tabIndex={0}
tooltipContent={i18n('acceptCall')}
/>
</>
) : (
<>
<CallButton
classSuffix="decline"
onClick={() => {
declineCall({ conversationId });
2020-06-04 18:16:19 +00:00
}}
tabIndex={0}
tooltipContent={i18n('declineCall')}
/>
<CallButton
classSuffix="accept-audio"
onClick={() => {
acceptCall({ conversationId, asVideoCall: false });
2020-06-04 18:16:19 +00:00
}}
tabIndex={0}
tooltipContent={i18n('acceptCall')}
/>
</>
)}
</div>
</div>
);
};