add user biography
This commit is contained in:
parent
f167780d15
commit
758d328a39
3 changed files with 54 additions and 24 deletions
|
|
@ -27,7 +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';
|
||||
import { UserBiography, UserPronoun } from '../../hooks/useUserProfile';
|
||||
|
||||
export function UserHero({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
|
|
@ -165,7 +165,7 @@ export function UserTimezone({ timezone }: { timezone: string }) {
|
|||
return (
|
||||
<Box as="span" alignItems="Center" gap="100">
|
||||
<Icon style={{ opacity: config.opacity.P300 }} size="50" src={Icons.Clock} />
|
||||
<Text as="span" size="T200" priority="300">
|
||||
<Text as="span" size="T200" priority="300" truncate>
|
||||
{time} local time{offset ? ` · ${offset}` : ` · ${timezone}`}
|
||||
</Text>
|
||||
</Box>
|
||||
|
|
@ -198,7 +198,9 @@ export function UserHeroName({ displayName, userId, pronouns }: UserHeroNameProp
|
|||
{pronouns?.map((pronoun) =>
|
||||
pronoun.summary ? (
|
||||
<Badge key={pronoun.summary} variant="Primary" fill="Soft" size="400">
|
||||
<Text size="L400">{pronoun.summary}</Text>
|
||||
<Text size="L400" truncate>
|
||||
{pronoun.summary}
|
||||
</Text>
|
||||
</Badge>
|
||||
) : undefined
|
||||
)}
|
||||
|
|
@ -206,3 +208,11 @@ export function UserHeroName({ displayName, userId, pronouns }: UserHeroNameProp
|
|||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export function UserHeroBiography({ bio }: { bio: UserBiography }) {
|
||||
return (
|
||||
<Text className={classNames(BreakWord, LineClamp3)} size="T200">
|
||||
<Linkify options={LINKIFY_OPTS}>{bio.body}</Linkify>
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,14 @@ 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, UserTimezone } from './UserHero';
|
||||
import {
|
||||
UserHero,
|
||||
UserHeroAvatar,
|
||||
UserHeroBiography,
|
||||
UserHeroCover,
|
||||
UserHeroName,
|
||||
UserTimezone,
|
||||
} from './UserHero';
|
||||
import { getMxIdServer } from '../../utils/matrix';
|
||||
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||
import {
|
||||
|
|
@ -123,11 +130,8 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) {
|
|||
/>
|
||||
)}
|
||||
</Box>
|
||||
{profile?.biography ? <UserHeroBiography bio={profile.biography} /> : null}
|
||||
{profile?.timezone && <UserTimezone timezone={profile.timezone} />}
|
||||
<Text size="T200">
|
||||
now hierarchy does not have room summary info we need to load it when we will be
|
||||
rendering it
|
||||
</Text>
|
||||
<Box alignItems="Center" gap="200" wrap="Wrap">
|
||||
{server && <ServerChip server={server} />}
|
||||
<ShareChip userId={userId} />
|
||||
|
|
|
|||
|
|
@ -5,24 +5,24 @@ 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 UserBiography = {
|
||||
body: string;
|
||||
formattedBody?: string;
|
||||
};
|
||||
|
||||
export type UserProfile = {
|
||||
avatarUrl?: string;
|
||||
displayName?: string;
|
||||
bannerUrl?: string;
|
||||
timezone?: string;
|
||||
pronouns?: UserPronoun[];
|
||||
biography?: UserBiography;
|
||||
};
|
||||
export const useUserProfile = (userId: string): UserProfile | undefined => {
|
||||
const ct = useClient();
|
||||
|
|
@ -36,15 +36,23 @@ export const useUserProfile = (userId: string): UserProfile | undefined => {
|
|||
|
||||
const [, profile] = await parseMatrixResp<
|
||||
GetProfileOK & {
|
||||
'chat.commet.profile_banner'?: string;
|
||||
'm.banner_url'?: string;
|
||||
'm.tz'?: string;
|
||||
'io.fsky.nyx.pronouns': PronounResponse[];
|
||||
'm.pronouns': PronounResponse[];
|
||||
'chat.commet.profile_banner'?: unknown;
|
||||
'm.banner_url'?: unknown;
|
||||
'm.tz'?: unknown;
|
||||
'io.fsky.nyx.pronouns': unknown;
|
||||
'm.pronouns': unknown;
|
||||
'm.biography': unknown;
|
||||
'gay.fomx.biography': unknown;
|
||||
}
|
||||
>(response);
|
||||
|
||||
const pronouns = profile?.['m.pronouns'] ?? profile?.['io.fsky.nyx.pronouns'];
|
||||
const bio = profile?.['m.biography'] ?? profile?.['gay.fomx.biography'];
|
||||
const bioText = ObjectReader.array(bio, 'm.text');
|
||||
|
||||
const plainBio = bioText?.find((i) => ObjectReader.string(i, 'mimetype') !== 'text/html');
|
||||
const htmlBio = bioText?.find((i) => ObjectReader.string(i, 'mimetype') === 'text/html');
|
||||
const bioBody = ObjectReader.string(plainBio, 'body') ?? ObjectReader.string(htmlBio, 'body');
|
||||
|
||||
return {
|
||||
avatarUrl: profile?.avatar_url || undefined,
|
||||
|
|
@ -53,11 +61,19 @@ export const useUserProfile = (userId: string): UserProfile | undefined => {
|
|||
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'),
|
||||
})),
|
||||
pronouns: Array.isArray(pronouns)
|
||||
? pronouns?.map((p) => ({
|
||||
grammaticalGender: ObjectReader.string(p, 'grammatical_gender'),
|
||||
language: ObjectReader.string(p, 'language'),
|
||||
summary: ObjectReader.string(p, 'summary'),
|
||||
}))
|
||||
: undefined,
|
||||
biography: bioBody
|
||||
? {
|
||||
body: bioBody,
|
||||
formattedBody: ObjectReader.string(htmlBio, 'body'),
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
}, [ct, userId]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue