2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-10-17 18:22:07 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import classNames from 'classnames';
|
2020-01-17 22:23:19 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props as AvatarProps } from './Avatar';
|
2022-12-09 20:37:45 +00:00
|
|
|
import { Avatar, AvatarSize } from './Avatar';
|
2021-09-17 22:24:21 +00:00
|
|
|
import { useRestoreFocus } from '../hooks/useRestoreFocus';
|
2019-10-17 18:22:07 +00:00
|
|
|
|
2021-12-01 17:24:00 +00:00
|
|
|
import type { LocalizerType, ThemeType } from '../types/Util';
|
2022-08-10 21:46:43 +00:00
|
|
|
import { Emojify } from './conversation/Emojify';
|
2019-10-17 18:22:07 +00:00
|
|
|
|
|
|
|
export type Props = {
|
|
|
|
readonly i18n: LocalizerType;
|
2021-12-01 17:24:00 +00:00
|
|
|
readonly theme: ThemeType;
|
2019-10-17 18:22:07 +00:00
|
|
|
|
2021-08-19 22:56:29 +00:00
|
|
|
hasPendingUpdate: boolean;
|
|
|
|
startUpdate: () => unknown;
|
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
onEditProfile: () => unknown;
|
2019-10-17 18:22:07 +00:00
|
|
|
onViewPreferences: () => unknown;
|
|
|
|
onViewArchive: () => unknown;
|
|
|
|
|
|
|
|
// Matches Popper's RefHandler type
|
2020-01-07 01:49:00 +00:00
|
|
|
innerRef?: React.Ref<HTMLDivElement>;
|
2019-10-17 18:22:07 +00:00
|
|
|
style: React.CSSProperties;
|
2022-09-28 16:27:52 +00:00
|
|
|
name?: string;
|
2022-12-09 20:37:45 +00:00
|
|
|
} & Omit<AvatarProps, 'onClick' | 'size'>;
|
2019-10-17 18:22:07 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function AvatarPopup(props: Props): JSX.Element {
|
2019-10-17 18:22:07 +00:00
|
|
|
const {
|
2021-08-19 22:56:29 +00:00
|
|
|
hasPendingUpdate,
|
2019-10-17 18:22:07 +00:00
|
|
|
i18n,
|
2020-07-24 01:35:32 +00:00
|
|
|
name,
|
2021-07-19 19:26:06 +00:00
|
|
|
onEditProfile,
|
2019-10-17 18:22:07 +00:00
|
|
|
onViewArchive,
|
2021-08-19 22:56:29 +00:00
|
|
|
onViewPreferences,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
|
|
|
startUpdate,
|
2019-10-17 18:22:07 +00:00
|
|
|
style,
|
2021-08-19 22:56:29 +00:00
|
|
|
title,
|
2019-10-17 18:22:07 +00:00
|
|
|
} = props;
|
|
|
|
|
2020-07-24 01:35:32 +00:00
|
|
|
const shouldShowNumber = Boolean(name || profileName);
|
2019-10-17 18:22:07 +00:00
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
// Note: mechanisms to dismiss this view are all in its host, MainHeader
|
|
|
|
|
|
|
|
// Focus first button after initial render, restore focus on teardown
|
2021-07-30 20:30:59 +00:00
|
|
|
const [focusRef] = useRestoreFocus();
|
2019-11-07 21:36:16 +00:00
|
|
|
|
2019-10-17 18:22:07 +00:00
|
|
|
return (
|
|
|
|
<div style={style} className="module-avatar-popup">
|
2021-07-19 19:26:06 +00:00
|
|
|
<button
|
|
|
|
className="module-avatar-popup__profile"
|
|
|
|
onClick={onEditProfile}
|
|
|
|
ref={focusRef}
|
|
|
|
type="button"
|
|
|
|
>
|
2022-12-09 20:37:45 +00:00
|
|
|
<Avatar {...props} size={AvatarSize.FORTY_EIGHT} />
|
2019-10-17 18:22:07 +00:00
|
|
|
<div className="module-avatar-popup__profile__text">
|
2020-07-27 18:07:09 +00:00
|
|
|
<div className="module-avatar-popup__profile__name">
|
2022-08-10 21:46:43 +00:00
|
|
|
<Emojify text={profileName || title} />
|
2020-07-27 18:07:09 +00:00
|
|
|
</div>
|
2020-07-24 01:35:32 +00:00
|
|
|
{shouldShowNumber ? (
|
2019-10-17 18:22:07 +00:00
|
|
|
<div className="module-avatar-popup__profile__number">
|
|
|
|
{phoneNumber}
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2021-07-19 19:26:06 +00:00
|
|
|
</button>
|
2019-10-17 18:22:07 +00:00
|
|
|
<hr className="module-avatar-popup__divider" />
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
2020-09-12 00:46:52 +00:00
|
|
|
type="button"
|
2019-11-07 21:36:16 +00:00
|
|
|
className="module-avatar-popup__item"
|
|
|
|
onClick={onViewPreferences}
|
|
|
|
>
|
2019-10-17 18:22:07 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-avatar-popup__item__icon',
|
|
|
|
'module-avatar-popup__item__icon-settings'
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<div className="module-avatar-popup__item__text">
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:mainMenuSettings')}
|
2019-10-17 18:22:07 +00:00
|
|
|
</div>
|
|
|
|
</button>
|
2020-09-12 00:46:52 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="module-avatar-popup__item"
|
|
|
|
onClick={onViewArchive}
|
|
|
|
>
|
2019-10-17 18:22:07 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-avatar-popup__item__icon',
|
|
|
|
'module-avatar-popup__item__icon-archive'
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<div className="module-avatar-popup__item__text">
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:avatarMenuViewArchive')}
|
2019-10-17 18:22:07 +00:00
|
|
|
</div>
|
|
|
|
</button>
|
2021-08-19 22:56:29 +00:00
|
|
|
{hasPendingUpdate && (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="module-avatar-popup__item"
|
|
|
|
onClick={startUpdate}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-avatar-popup__item__icon',
|
|
|
|
'module-avatar-popup__item__icon--update'
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<div className="module-avatar-popup__item__text">
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:avatarMenuUpdateAvailable')}
|
2021-08-19 22:56:29 +00:00
|
|
|
</div>
|
|
|
|
<div className="module-avatar-popup__item--badge" />
|
|
|
|
</button>
|
|
|
|
)}
|
2019-10-17 18:22:07 +00:00
|
|
|
</div>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|