diff --git a/src/app/components/user-profile/UserChips.tsx b/src/app/components/user-profile/UserChips.tsx index 296c52b3..f09507f7 100644 --- a/src/app/components/user-profile/UserChips.tsx +++ b/src/app/components/user-profile/UserChips.tsx @@ -1,4 +1,4 @@ -import React, { MouseEventHandler, useCallback, useMemo, useState } from 'react'; +import React, { MouseEventHandler, useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import FocusTrap from 'focus-trap-react'; import { isKeyHotkey } from 'is-hotkey'; @@ -19,13 +19,12 @@ import { Scroll, Avatar, } from 'folds'; -import { putAccountData } from 'neurone/lib/api/matrix/client/v3/user'; import { getMxIdServer } from '../../utils/matrix'; import { useCloseUserRoomProfile } from '../../state/hooks/userRoomProfile'; import { stopPropagation } from '../../utils/keyboard'; import { copyToClipboard } from '../../utils/dom'; import { getExploreServerPath } from '../../pages/pathUtils'; -import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback'; +import { AsyncStatus } from '../../hooks/useAsyncCallback'; import { factoryRoomIdByAtoZ } from '../../utils/sort'; import { useMutualRooms } from '../../hooks/useMutualRooms'; import { useRoomNavigate } from '../../hooks/useRoomNavigate'; @@ -35,11 +34,9 @@ import { RoomAvatar, RoomIcon } from '../room-avatar'; import { nameInitials } from '../../utils/common'; import { getMatrixToUser } from '../../plugins/matrix-to'; import { useTimeoutToggle } from '../../hooks/useTimeoutToggle'; -import { getIgnoredUsersContent, useIgnoredUsers } from '../../hooks/useIgnoredUsers'; import { CutoutCard } from '../cutout-card'; import { SettingTile } from '../setting-tile'; import { useClient } from '../../hooks/useClient'; -import { AccountDataType } from '../../../types/matrix/accountData'; import { useRoomHeroes } from '../../hooks/storage/useRoomHeros'; import { useGetRoomName } from '../../hooks/storage/useGetRoomName'; import { useGetRoomAvatar } from '../../hooks/storage/useGetRoomAvatar'; @@ -447,86 +444,3 @@ export function IgnoredUserAlert() { ); } - -export function OptionsChip({ userId }: { userId: string }) { - const ct = useClient(); - const [cords, setCords] = useState(); - - const open: MouseEventHandler = (evt) => { - setCords(evt.currentTarget.getBoundingClientRect()); - }; - - const close = () => setCords(undefined); - - const ignoredUsers = useIgnoredUsers(); - const ignored = ignoredUsers.includes(userId); - - const [ignoreState, toggleIgnore] = useAsyncCallback( - useCallback(async () => { - const users = ignoredUsers.filter((u) => u !== userId); - if (!ignored) users.push(userId); - - return ct.requestAuthJSON( - putAccountData({ - pathParams: { userId: ct.session.userId, type: AccountDataType.IgnoredUserList }, - body: getIgnoredUsersContent(users), - }) - ); - }, [ct, ignoredUsers, userId, ignored]) - ); - const ignoring = ignoreState.status === AsyncStatus.Loading; - - return ( - isKeyHotkey('arrowdown', evt), - isKeyBackward: (evt: KeyboardEvent) => isKeyHotkey('arrowup', evt), - }} - > - -
- { - toggleIgnore(); - close(); - }} - before={ - ignoring ? ( - - ) : ( - - ) - } - disabled={ignoring} - > - {ignored ? 'Unblock User' : 'Block User'} - -
-
- - } - > - - {ignoring ? ( - - ) : ( - - )} - -
- ); -} diff --git a/src/app/components/user-profile/UserHero.tsx b/src/app/components/user-profile/UserHero.tsx index 6684eca0..df72b9a7 100644 --- a/src/app/components/user-profile/UserHero.tsx +++ b/src/app/components/user-profile/UserHero.tsx @@ -1,7 +1,9 @@ import React, { ReactNode, useState } from 'react'; import { Avatar, + Badge, Box, + config, Icon, Icons, Modal, @@ -9,8 +11,6 @@ import { OverlayBackdrop, OverlayCenter, Text, - Tooltip, - TooltipProvider, } from 'folds'; import classNames from 'classnames'; import FocusTrap from 'focus-trap-react'; @@ -19,7 +19,7 @@ import * as css from './styles.css'; import { UserAvatar } from '../user-avatar'; import colorMXID from '../../../util/colorMXID'; import { getMxIdLocalPart } from '../../utils/matrix'; -import { BreakWord, DotDivider, HoverUnderline, LineClamp3 } from '../../styles/Text.css'; +import { BreakWord, LineClamp3 } from '../../styles/Text.css'; import { UserPresence } from '../../hooks/useUserPresence'; import { AvatarPresence, PresenceBadge } from '../presence'; import { ImageViewer } from '../image-viewer'; @@ -27,6 +27,7 @@ import { stopPropagation } from '../../utils/keyboard'; import { LINKIFY_OPTS } from '../../plugins/react-custom-html-parser'; import { useSetting } from '../../state/hooks/settings'; import { settingsAtom } from '../../state/settings'; +import { UserPronoun } from '../../hooks/useUserProfile'; export function UserHero({ children }: { children: ReactNode }) { return ( @@ -139,47 +140,49 @@ export function UserTimezone({ timezone }: { timezone: string }) { const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock'); let time: string | undefined; + let offset: string | undefined; + try { - time = new Intl.DateTimeFormat('en-US', { + const parts = new Intl.DateTimeFormat('en-US', { timeZone: timezone, hour: '2-digit', minute: '2-digit', hour12: !hour24Clock, - }).format(new Date()); + timeZoneName: 'shortOffset', + }).formatToParts(new Date()); + + time = parts + .filter((p) => (p.type !== 'timeZoneName' && p.type !== 'literal') || p.type === 'literal') + .map((p) => p.value) + .join('') + .trim(); + + offset = parts.find((p) => p.type === 'timeZoneName')?.value; // e.g. "GMT+5:30" } catch (e) { console.error(e); } return ( - - {timezone} - - } - > - {(triggerRef) => ( - - {time} - - )} - + + + + {time} local time{offset ? ` · ${offset}` : ` · ${timezone}`} + + ); } type UserHeroNameProps = { displayName?: string; userId: string; - timezone?: string; + pronouns?: UserPronoun[]; }; -export function UserHeroName({ displayName, userId, timezone }: UserHeroNameProps) { +export function UserHeroName({ displayName, userId, pronouns }: UserHeroNameProps) { const username = getMxIdLocalPart(userId); return ( - + - + @{username} - {timezone && } - {timezone && } + {pronouns?.map((pronoun) => + pronoun.summary ? ( + + {pronoun.summary} + + ) : undefined + )} ); diff --git a/src/app/components/user-profile/UserModeration.tsx b/src/app/components/user-profile/UserModeration.tsx index 0bc4d601..0db24f4b 100644 --- a/src/app/components/user-profile/UserModeration.tsx +++ b/src/app/components/user-profile/UserModeration.tsx @@ -1,7 +1,27 @@ -import { Box, Button, color, config, Icon, Icons, Spinner, Text, Input } from 'folds'; -import React, { useCallback, useRef } from 'react'; +import { + Box, + Button, + color, + config, + Icon, + Icons, + Spinner, + Text, + Input, + RectCords, + PopOut, + Menu, + MenuItem, + toRem, + Line, + IconButton, +} from 'folds'; +import React, { MouseEventHandler, useCallback, useRef, useState } from 'react'; import { postBan, postInvite, postKick, postUnban } from 'neurone/lib/api/matrix/client/v3/rooms'; import { parseMatrixResp } from 'neurone/lib/matrix-request'; +import { putAccountData } from 'neurone/lib/api/matrix/client/v3/user'; +import FocusTrap from 'focus-trap-react'; +import { isKeyHotkey } from 'is-hotkey'; import { useRoom } from '../../hooks/useRoom'; import { CutoutCard } from '../cutout-card'; import { SettingTile } from '../setting-tile'; @@ -11,6 +31,9 @@ import { useSetting } from '../../state/hooks/settings'; import { settingsAtom } from '../../state/settings'; import { timeDayMonYear, timeHourMinute } from '../../utils/time'; import { useClient } from '../../hooks/useClient'; +import { getIgnoredUsersContent, useIgnoredUsers } from '../../hooks/useIgnoredUsers'; +import { AccountDataType } from '../../../types/matrix/accountData'; +import { stopPropagation } from '../../utils/keyboard'; type UserKickAlertProps = { reason?: string; @@ -293,97 +316,206 @@ export function UserModeration({ userId, canKick, canBan, canInvite }: UserModer if (!canBan && !canKick && !canInvite) return null; return ( - - - - Moderation - + + Moderation + + {kickState.status === AsyncStatus.Error && ( + + {kickState.error.message} + + )} + {banState.status === AsyncStatus.Error && ( + + {banState.error.message} + + )} + {inviteState.status === AsyncStatus.Error && ( + + {inviteState.error.message} + + )} + + + {canInvite && ( + + ) : ( + + ) + } + onClick={invite} disabled={disabled} - /> - {kickState.status === AsyncStatus.Error && ( - - {kickState.error.message} + > + + Invite to Room - )} - {banState.status === AsyncStatus.Error && ( - - {banState.error.message} + + )} + {canKick && ( + + ) : ( + + ) + } + onClick={kick} + disabled={disabled} + > + + Kick from Room - )} - {inviteState.status === AsyncStatus.Error && ( - - {inviteState.error.message} + + )} + {canBan && ( + + ) : ( + + ) + } + onClick={ban} + disabled={disabled} + > + + Ban from Room - )} - - - {canInvite && ( - - )} - {canKick && ( - - )} - {canBan && ( - - )} - + + )} ); } + +export function OptionsButton({ userId, canBan, canInvite, canKick }: UserModerationProps) { + const ct = useClient(); + const [cords, setCords] = useState(); + + const open: MouseEventHandler = (evt) => { + setCords(evt.currentTarget.getBoundingClientRect()); + }; + + const close = () => setCords(undefined); + + const ignoredUsers = useIgnoredUsers(); + const ignored = ignoredUsers.includes(userId); + + const [ignoreState, toggleIgnore] = useAsyncCallback( + useCallback(async () => { + const users = ignoredUsers.filter((u) => u !== userId); + if (!ignored) users.push(userId); + + return ct.requestAuthJSON( + putAccountData({ + pathParams: { userId: ct.session.userId, type: AccountDataType.IgnoredUserList }, + body: getIgnoredUsersContent(users), + }) + ); + }, [ct, ignoredUsers, userId, ignored]) + ); + const ignoring = ignoreState.status === AsyncStatus.Loading; + + return ( + isKeyHotkey('arrowdown', evt), + isKeyBackward: (evt: KeyboardEvent) => isKeyHotkey('arrowup', evt), + }} + > + + + {(canInvite || canBan || canKick) && ( + <> +
+ +
+ + + )} + + { + toggleIgnore(); + close(); + }} + after={ + ignoring ? ( + + ) : ( + + ) + } + disabled={ignoring} + > + + {ignored ? 'Unblock User' : 'Block User'} + + + +
+
+ + } + > + + + +
+ ); +} diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index c7a61ca0..9b4fc755 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -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, UserHeroAvatar, UserHeroCover, UserHeroName } from './UserHero'; +import { UserHero, UserHeroAvatar, UserHeroCover, UserHeroName, UserTimezone } from './UserHero'; import { getMxIdServer } from '../../utils/matrix'; import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { @@ -12,10 +12,10 @@ import { } from '../../hooks/usePowerLevels'; import { useRoom } from '../../hooks/useRoom'; import { useUserPresence } from '../../hooks/useUserPresence'; -import { IgnoredUserAlert, MutualRoomsChip, OptionsChip, ServerChip, ShareChip } from './UserChips'; +import { IgnoredUserAlert, MutualRoomsChip, ServerChip, ShareChip } from './UserChips'; import { useCloseUserRoomProfile } from '../../state/hooks/userRoomProfile'; import { PowerChip } from './PowerChip'; -import { UserInviteAlert, UserBanAlert, UserModeration, UserKickAlert } from './UserModeration'; +import { UserInviteAlert, UserBanAlert, UserKickAlert, OptionsButton } from './UserModeration'; import { useIgnoredUsers } from '../../hooks/useIgnoredUsers'; import { Membership } from '../../../types/matrix/room'; import { useRoomCreators } from '../../hooks/useRoomCreators'; @@ -33,7 +33,6 @@ import { usePowerLevelTagsState, } from '../../hooks/usePowerLevelTags'; import { useUserProfile } from '../../hooks/useUserProfile'; -import { UserActionButton } from './styles.css'; type UserRoomProfileProps = { userId: string; @@ -101,21 +100,6 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) { bannerUrl={bannerUrl} hasStatus={!!presence?.status} /> - {userId !== myUserId && ( - - - - )} - + + + {userId !== myUserId && ( + + )} + + {profile?.timezone && } + + now hierarchy does not have room summary info we need to load it when we will be + rendering it + {server && } {creator ? : } {userId !== myUserId && } - {userId !== myUserId && } {ignored && } @@ -165,12 +163,21 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) { ts={memberEventResult.value.event.origin_server_ts} /> )} - + {userId !== myUserId && ( + + + + )}
diff --git a/src/app/components/user-profile/styles.css.ts b/src/app/components/user-profile/styles.css.ts index 7ea20903..c254ba42 100644 --- a/src/app/components/user-profile/styles.css.ts +++ b/src/app/components/user-profile/styles.css.ts @@ -106,11 +106,3 @@ 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}`, -}); diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index 0dfdb82e..97948e63 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -2,13 +2,27 @@ import { useCallback } from 'react'; import { useQuery } from '@tanstack/react-query'; import { getProfile, GetProfileOK } from 'neurone/lib/api/matrix/client/v3/profile'; import { parseMatrixResp } from 'neurone/lib/matrix-request'; +import { ObjectReader } from 'neurone/lib/utils'; import { useClient } from './useClient'; +type PronounResponse = { + grammatical_gender?: string; + language?: string; + summary?: string; +}; + +export type UserPronoun = { + grammaticalGender?: string; + language?: string; + summary?: string; +}; + export type UserProfile = { avatarUrl?: string; displayName?: string; bannerUrl?: string; timezone?: string; + pronouns?: UserPronoun[]; }; export const useUserProfile = (userId: string): UserProfile | undefined => { const ct = useClient(); @@ -25,14 +39,25 @@ export const useUserProfile = (userId: string): UserProfile | undefined => { 'chat.commet.profile_banner'?: string; 'm.banner_url'?: string; 'm.tz'?: string; + 'io.fsky.nyx.pronouns': PronounResponse[]; + 'm.pronouns': PronounResponse[]; } >(response); + const pronouns = profile?.['m.pronouns'] ?? profile?.['io.fsky.nyx.pronouns']; + return { avatarUrl: profile?.avatar_url || undefined, displayName: profile?.displayname || undefined, - bannerUrl: profile?.['m.banner_url'] ?? profile?.['chat.commet.profile_banner'] ?? undefined, - timezone: profile?.['m.tz'] ?? undefined, + bannerUrl: + ObjectReader.string(profile, 'm.banner_url') ?? + ObjectReader.string(profile, 'chat.commet.profile_banner'), + timezone: ObjectReader.string(profile, 'm.tz'), + pronouns: pronouns?.map((p) => ({ + grammaticalGender: ObjectReader.string(p, 'grammatical_gender'), + language: ObjectReader.string(p, 'language'), + summary: ObjectReader.string(p, 'summary'), + })), }; }, [ct, userId]);