mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 22:40:29 +03:00
124 lines
3.9 KiB
TypeScript
124 lines
3.9 KiB
TypeScript
import React, { useState } from 'react';
|
|
import {
|
|
Avatar,
|
|
Box,
|
|
Icon,
|
|
Icons,
|
|
Modal,
|
|
Overlay,
|
|
OverlayBackdrop,
|
|
OverlayCenter,
|
|
Text,
|
|
} from 'folds';
|
|
import classNames from 'classnames';
|
|
import FocusTrap from 'focus-trap-react';
|
|
import * as css from './styles.css';
|
|
import { UserAvatar } from '../user-avatar';
|
|
import colorMXID from '../../../util/colorMXID';
|
|
import { getMxIdLocalPart } from '../../utils/matrix';
|
|
import { BreakWord, LineClamp3 } from '../../styles/Text.css';
|
|
import { UserPresence } from '../../hooks/useUserPresence';
|
|
import { AvatarPresence, PresenceBadge } from '../presence';
|
|
import { ImageViewer } from '../image-viewer';
|
|
import { stopPropagation } from '../../utils/keyboard';
|
|
import { extendedProfileFields } from '../../hooks/useExtendedProfile';
|
|
|
|
type UserHeroProps = {
|
|
userId: string;
|
|
avatarUrl?: string;
|
|
presence?: UserPresence;
|
|
};
|
|
export function UserHero({ userId, avatarUrl, presence }: UserHeroProps) {
|
|
const [viewAvatar, setViewAvatar] = useState<string>();
|
|
|
|
return (
|
|
<Box direction="Column" className={css.UserHero}>
|
|
<div
|
|
className={css.UserHeroCoverContainer}
|
|
style={{
|
|
backgroundColor: colorMXID(userId),
|
|
filter: avatarUrl ? undefined : 'brightness(50%)',
|
|
}}
|
|
>
|
|
{avatarUrl && (
|
|
<img className={css.UserHeroCover} src={avatarUrl} alt={userId} draggable="false" />
|
|
)}
|
|
</div>
|
|
<div className={css.UserHeroAvatarContainer}>
|
|
<AvatarPresence
|
|
className={css.UserAvatarContainer}
|
|
badge={
|
|
presence && <PresenceBadge presence={presence.presence} status={presence.status} />
|
|
}
|
|
>
|
|
<Avatar
|
|
as={avatarUrl ? 'button' : 'div'}
|
|
onClick={avatarUrl ? () => setViewAvatar(avatarUrl) : undefined}
|
|
className={css.UserHeroAvatar}
|
|
size="500"
|
|
>
|
|
<UserAvatar
|
|
className={css.UserHeroAvatarImg}
|
|
userId={userId}
|
|
src={avatarUrl}
|
|
alt={userId}
|
|
renderFallback={() => <Icon size="500" src={Icons.User} filled />}
|
|
/>
|
|
</Avatar>
|
|
</AvatarPresence>
|
|
{viewAvatar && (
|
|
<Overlay open backdrop={<OverlayBackdrop />}>
|
|
<OverlayCenter>
|
|
<FocusTrap
|
|
focusTrapOptions={{
|
|
initialFocus: false,
|
|
onDeactivate: () => setViewAvatar(undefined),
|
|
clickOutsideDeactivates: true,
|
|
escapeDeactivates: stopPropagation,
|
|
}}
|
|
>
|
|
<Modal size="500" onContextMenu={(evt: any) => evt.stopPropagation()}>
|
|
<ImageViewer
|
|
src={viewAvatar}
|
|
alt={userId}
|
|
requestClose={() => setViewAvatar(undefined)}
|
|
/>
|
|
</Modal>
|
|
</FocusTrap>
|
|
</OverlayCenter>
|
|
</Overlay>
|
|
)}
|
|
</div>
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
type UserHeroNameProps = {
|
|
displayName?: string;
|
|
userId: string;
|
|
extendedProfile?: extendedProfileFields;
|
|
};
|
|
export function UserHeroName({ displayName, userId, extendedProfile }: UserHeroNameProps) {
|
|
const username = getMxIdLocalPart(userId);
|
|
const pronouns = extendedProfile?.["io.fsky.nyx.pronouns"];
|
|
|
|
return (
|
|
<Box grow="Yes" direction="Column" gap="0">
|
|
<Box alignItems="Baseline" gap="200" wrap="Wrap">
|
|
<Text
|
|
size="H4"
|
|
className={classNames(BreakWord, LineClamp3)}
|
|
title={displayName ?? username}
|
|
>
|
|
{displayName ?? username ?? userId}
|
|
</Text>
|
|
</Box>
|
|
<Box alignItems="Start" gap="100" wrap="Wrap" direction='Column'>
|
|
<Text size="T200" className={classNames(BreakWord, LineClamp3)} title={username}>
|
|
@{username}
|
|
{pronouns && <span> · {pronouns.map(({ summary }) => summary).join(", ")}</span>}
|
|
</Text>
|
|
</Box>
|
|
</Box>
|
|
);
|
|
}
|