move profile message button upwards
This commit is contained in:
parent
9a0bba256c
commit
199e66b117
4 changed files with 148 additions and 109 deletions
|
|
@ -17,7 +17,7 @@ import { usePresenceLabel } from '../../hooks/useUserPresence';
|
|||
|
||||
const PresenceToColor: Record<Presence, MainColor> = {
|
||||
online: 'Success',
|
||||
unavailable: 'Warning',
|
||||
unavailable: 'Critical',
|
||||
offline: 'Secondary',
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState } from 'react';
|
||||
import React, { ReactNode, useState } from 'react';
|
||||
import {
|
||||
Avatar,
|
||||
Box,
|
||||
|
|
@ -28,103 +28,127 @@ import { LINKIFY_OPTS } from '../../plugins/react-custom-html-parser';
|
|||
import { useSetting } from '../../state/hooks/settings';
|
||||
import { settingsAtom } from '../../state/settings';
|
||||
|
||||
type UserHeroProps = {
|
||||
export function UserHero({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<Box direction="Column" className={css.UserHero}>
|
||||
{children}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export function UserHeroCover({
|
||||
userId,
|
||||
avatarUrl,
|
||||
bannerUrl,
|
||||
hasStatus,
|
||||
}: {
|
||||
userId: string;
|
||||
avatarUrl?: string;
|
||||
bannerUrl?: string;
|
||||
hasStatus: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={css.UserHeroCoverContainer}
|
||||
style={{
|
||||
backgroundColor: colorMXID(userId),
|
||||
filter: bannerUrl && !hasStatus ? undefined : 'brightness(50%)',
|
||||
}}
|
||||
>
|
||||
{bannerUrl && (
|
||||
<img
|
||||
className={classNames(
|
||||
css.UserHeroCover,
|
||||
avatarUrl === bannerUrl && css.UserHeroCoverBlurred
|
||||
)}
|
||||
src={bannerUrl}
|
||||
alt={userId}
|
||||
draggable="false"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
type UserHeroAvatarProps = {
|
||||
userId: string;
|
||||
avatarUrl?: string;
|
||||
presence?: UserPresence;
|
||||
};
|
||||
export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroProps) {
|
||||
export function UserHeroAvatar({ userId, avatarUrl, presence }: UserHeroAvatarProps) {
|
||||
const [viewAvatar, setViewAvatar] = useState<string>();
|
||||
|
||||
const { status } = presence ?? {};
|
||||
|
||||
return (
|
||||
<Box direction="Column" className={css.UserHero}>
|
||||
<div
|
||||
className={css.UserHeroCoverContainer}
|
||||
style={{
|
||||
backgroundColor: colorMXID(userId),
|
||||
filter: bannerUrl && !status ? undefined : 'brightness(50%)',
|
||||
}}
|
||||
<div className={css.UserHeroAvatarContainer}>
|
||||
<AvatarPresence
|
||||
className={css.UserAvatarContainer}
|
||||
badge={presence && <PresenceBadge presence={presence.presence} />}
|
||||
>
|
||||
{bannerUrl && (
|
||||
<img
|
||||
className={classNames(
|
||||
css.UserHeroCover,
|
||||
avatarUrl === bannerUrl && css.UserHeroCoverBlurred
|
||||
)}
|
||||
src={bannerUrl}
|
||||
alt={userId}
|
||||
draggable="false"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className={css.UserHeroAvatarContainer}>
|
||||
<AvatarPresence
|
||||
className={css.UserAvatarContainer}
|
||||
badge={presence && <PresenceBadge presence={presence.presence} />}
|
||||
<Avatar
|
||||
as={avatarUrl ? 'button' : 'div'}
|
||||
onClick={avatarUrl ? () => setViewAvatar(avatarUrl) : undefined}
|
||||
className={css.UserHeroAvatar}
|
||||
size="500"
|
||||
>
|
||||
<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>
|
||||
{status && (
|
||||
<div className={css.UserHeroStatus}>
|
||||
<div className={css.UserHeroStatusContent}>
|
||||
<Text className={classNames(BreakWord, LineClamp3)} size="T200">
|
||||
<Linkify options={LINKIFY_OPTS}>{status}</Linkify>
|
||||
</Text>
|
||||
</div>
|
||||
<UserAvatar
|
||||
className={css.UserHeroAvatarImg}
|
||||
userId={userId}
|
||||
src={avatarUrl}
|
||||
alt={userId}
|
||||
renderFallback={() => <Icon size="500" src={Icons.User} filled />}
|
||||
/>
|
||||
</Avatar>
|
||||
</AvatarPresence>
|
||||
{status && (
|
||||
<div className={css.UserHeroStatus}>
|
||||
<div className={css.UserHeroStatusContent}>
|
||||
<Text title={status} className={classNames(BreakWord, LineClamp3)} size="T200">
|
||||
<Linkify options={LINKIFY_OPTS}>{status}</Linkify>
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
{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>
|
||||
</div>
|
||||
)}
|
||||
{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>
|
||||
);
|
||||
}
|
||||
|
||||
export function UserTimezone({ timezone }: { timezone: string }) {
|
||||
const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock');
|
||||
|
||||
const time = new Intl.DateTimeFormat('en-US', {
|
||||
timeZone: timezone,
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: !hour24Clock,
|
||||
}).format(new Date());
|
||||
let time: string | undefined;
|
||||
try {
|
||||
time = new Intl.DateTimeFormat('en-US', {
|
||||
timeZone: timezone,
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: !hour24Clock,
|
||||
}).format(new Date());
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
return (
|
||||
<TooltipProvider
|
||||
|
|
@ -155,7 +179,7 @@ export function UserHeroName({ displayName, userId, timezone }: UserHeroNameProp
|
|||
|
||||
return (
|
||||
<Box grow="Yes" direction="Column" gap="100">
|
||||
<Box alignItems="Baseline" gap="200" wrap="Wrap">
|
||||
<Box alignItems="Baseline" gap="100" wrap="Wrap">
|
||||
<Text
|
||||
size="H4"
|
||||
className={classNames(BreakWord, LineClamp3)}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Box, Button, config, Icon, Icons, Text } from 'folds';
|
|||
import React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { ObjectReader } from 'neurone/lib/utils';
|
||||
import { UserHero, UserHeroName } from './UserHero';
|
||||
import { UserHero, UserHeroAvatar, UserHeroCover, UserHeroName } from './UserHero';
|
||||
import { getMxIdServer } from '../../utils/matrix';
|
||||
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||
import {
|
||||
|
|
@ -33,6 +33,7 @@ import {
|
|||
usePowerLevelTagsState,
|
||||
} from '../../hooks/usePowerLevelTags';
|
||||
import { useUserProfile } from '../../hooks/useUserProfile';
|
||||
import { UserActionButton } from './styles.css';
|
||||
|
||||
type UserRoomProfileProps = {
|
||||
userId: string;
|
||||
|
|
@ -93,35 +94,41 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) {
|
|||
<PowerLevelsContextProvider value={powerLevels}>
|
||||
<PowerLevelTagsContextProvider value={powerLevelTags}>
|
||||
<Box direction="Column">
|
||||
<UserHero
|
||||
userId={userId}
|
||||
avatarUrl={avatarUrl}
|
||||
bannerUrl={bannerUrl}
|
||||
presence={presence && presence.lastActiveTs !== 0 ? presence : undefined}
|
||||
/>
|
||||
<UserHero>
|
||||
<UserHeroCover
|
||||
userId={userId}
|
||||
avatarUrl={avatarUrl}
|
||||
bannerUrl={bannerUrl}
|
||||
hasStatus={!!presence?.status}
|
||||
/>
|
||||
{userId !== myUserId && (
|
||||
<Box grow="Yes" style={{ position: 'relative' }}>
|
||||
<Button
|
||||
className={UserActionButton}
|
||||
size="300"
|
||||
variant="Primary"
|
||||
fill="Solid"
|
||||
radii="300"
|
||||
before={<Icon size="50" src={Icons.Message} filled />}
|
||||
onClick={handleMessage}
|
||||
>
|
||||
<Text size="B300">Message</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
<UserHeroAvatar
|
||||
userId={userId}
|
||||
avatarUrl={avatarUrl}
|
||||
presence={presence && presence.lastActiveTs !== 0 ? presence : undefined}
|
||||
/>
|
||||
</UserHero>
|
||||
<Box direction="Column" gap="500" style={{ padding: config.space.S400 }}>
|
||||
<Box direction="Column" gap="400">
|
||||
<Box gap="400" alignItems="Start">
|
||||
<UserHeroName
|
||||
displayName={displayName}
|
||||
userId={userId}
|
||||
timezone={profile?.timezone}
|
||||
/>
|
||||
{userId !== myUserId && (
|
||||
<Box shrink="No">
|
||||
<Button
|
||||
size="300"
|
||||
variant="Primary"
|
||||
fill="Solid"
|
||||
radii="300"
|
||||
before={<Icon size="50" src={Icons.Message} filled />}
|
||||
onClick={handleMessage}
|
||||
>
|
||||
<Text size="B300">Message</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
<UserHeroName
|
||||
displayName={displayName}
|
||||
userId={userId}
|
||||
timezone={profile?.timezone}
|
||||
/>
|
||||
<Box alignItems="Center" gap="200" wrap="Wrap">
|
||||
{server && <ServerChip server={server} />}
|
||||
<ShareChip userId={userId} />
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ export const UserHeroStatus = style({
|
|||
position: 'absolute',
|
||||
left: toRem(78),
|
||||
bottom: toRem(58),
|
||||
marginRight: config.space.S100,
|
||||
marginRight: config.space.S400,
|
||||
|
||||
animation: `${StatusAnime} 100ms`,
|
||||
|
||||
|
|
@ -106,3 +106,11 @@ export const UserHeroStatusContent = style({
|
|||
color: color.Surface.OnContainer,
|
||||
borderRadius: config.radii.R500,
|
||||
});
|
||||
|
||||
export const UserActionButton = style({
|
||||
position: 'absolute',
|
||||
right: config.space.S400,
|
||||
zIndex: 1,
|
||||
transform: 'translateY(-10%)',
|
||||
outline: `${config.borderWidth.B600} solid ${color.Surface.Container}`,
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue