diff --git a/src/lib/strings/pronouns.ts b/src/lib/strings/pronouns.ts new file mode 100644 index 000000000..33dae6c32 --- /dev/null +++ b/src/lib/strings/pronouns.ts @@ -0,0 +1,13 @@ +import {forceLTR} from './bidi' + +export function sanitizePronouns( + pronouns: string, + forceLeftToRight = true, +): string { + if (!pronouns || pronouns.trim() === '') { + return '' + } + + const trimmed = pronouns.trim().toLowerCase() + return forceLeftToRight ? forceLTR(trimmed) : trimmed +} diff --git a/src/screens/Profile/Header/EditProfileDialog.tsx b/src/screens/Profile/Header/EditProfileDialog.tsx index 68b7777bc..d633ecbb2 100644 --- a/src/screens/Profile/Header/EditProfileDialog.tsx +++ b/src/screens/Profile/Header/EditProfileDialog.tsx @@ -27,6 +27,7 @@ import {useSimpleVerificationState} from '#/components/verification' const DISPLAY_NAME_MAX_GRAPHEMES = 64 const DESCRIPTION_MAX_GRAPHEMES = 256 +const PRONOUNS_MAX_GRAPHEMES = 20 export function EditProfileDialog({ profile, @@ -114,6 +115,8 @@ function DialogInner({ const [displayName, setDisplayName] = useState(initialDisplayName) const initialDescription = profile.description || '' const [description, setDescription] = useState(initialDescription) + const initialPronouns = profile.pronouns || '' + const [pronouns, setPronouns] = useState(initialPronouns) const [userBanner, setUserBanner] = useState( profile.banner, ) @@ -130,6 +133,7 @@ function DialogInner({ const dirty = displayName !== initialDisplayName || description !== initialDescription || + pronouns !== initialPronouns || userAvatar !== profile.avatar || userBanner !== profile.banner @@ -181,6 +185,7 @@ function DialogInner({ updates: { displayName: displayName.trimEnd(), description: description.trimEnd(), + pronouns: pronouns.trimEnd().toLowerCase(), }, newUserAvatar, newUserBanner, @@ -197,6 +202,7 @@ function DialogInner({ control, displayName, description, + pronouns, newUserAvatar, newUserBanner, setImageError, @@ -211,6 +217,10 @@ function DialogInner({ text: description, maxCount: DESCRIPTION_MAX_GRAPHEMES, }) + const pronounsTooLong = isOverMaxGraphemeCount({ + text: pronouns, + maxCount: PRONOUNS_MAX_GRAPHEMES, + }) const cancelButton = useCallback( () => ( @@ -239,7 +249,8 @@ function DialogInner({ !dirty || isUpdatingProfile || displayNameTooLong || - descriptionTooLong + descriptionTooLong || + pronounsTooLong } size="small" color="primary" @@ -260,6 +271,7 @@ function DialogInner({ isUpdatingProfile, displayNameTooLong, descriptionTooLong, + pronounsTooLong, ], ) @@ -387,6 +399,35 @@ function DialogInner({ )} + + + + Pronouns + + + + + {pronounsTooLong && ( + + + + )} + ) diff --git a/src/screens/Profile/Header/Handle.tsx b/src/screens/Profile/Header/Handle.tsx index a495554fe..0de4609f9 100644 --- a/src/screens/Profile/Header/Handle.tsx +++ b/src/screens/Profile/Header/Handle.tsx @@ -4,6 +4,7 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {isInvalidHandle, sanitizeHandle} from '#/lib/strings/handles' +import {sanitizePronouns} from '#/lib/strings/pronouns' import {type Shadow} from '#/state/cache/types' import {atoms as a, useTheme, web} from '#/alf' import {NewskieDialog} from '#/components/NewskieDialog' @@ -21,6 +22,7 @@ export function ProfileHeaderHandle({ const {_} = useLingui() const invalidHandle = isInvalidHandle(profile.handle) const blockHide = profile.viewer?.blocking || profile.viewer?.blockedBy + const pronouns = profile.pronouns return ( ) : undefined} - - {invalidHandle - ? _(msg`⚠Invalid Handle`) - : sanitizeHandle( - profile.handle, - '@', - // forceLTR handled by CSS above on web - IS_NATIVE, - )} - + + + {invalidHandle + ? _(msg`⚠Invalid Handle`) + : sanitizeHandle( + profile.handle, + '@', + // forceLTR handled by CSS above on web + IS_NATIVE, + )} + + {pronouns && ( + + {sanitizePronouns(pronouns, IS_NATIVE)} + + )} + ) } diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index 98ac993fe..ebf01b4e4 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -185,6 +185,9 @@ export function useProfileUpdateMutation() { } else { next.displayName = updates.displayName next.description = updates.description + if ('pronouns' in updates) { + next.pronouns = updates.pronouns + } if ('pinnedPost' in updates) { next.pinnedPost = updates.pinnedPost } @@ -231,7 +234,8 @@ export function useProfileUpdateMutation() { } return ( res.data.displayName === updates.displayName && - res.data.description === updates.description + res.data.description === updates.description && + res.data.pronouns === updates.pronouns ) }), ) diff --git a/src/view/com/composer/ComposerReplyTo.tsx b/src/view/com/composer/ComposerReplyTo.tsx index 462779151..4d30e235e 100644 --- a/src/view/com/composer/ComposerReplyTo.tsx +++ b/src/view/com/composer/ComposerReplyTo.tsx @@ -12,6 +12,7 @@ import {useLingui} from '@lingui/react' import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeHandle} from '#/lib/strings/handles' +import {sanitizePronouns} from '#/lib/strings/pronouns' import {type ComposerOptsPostRef} from '#/state/shell/composer' import {PreviewableUserAvatar} from '#/view/com/util/UserAvatar' import {atoms as a, useTheme, web} from '#/alf' @@ -117,6 +118,18 @@ export function ComposerReplyTo({replyTo}: {replyTo: ComposerOptsPostRef}) { /> )} + {typeof replyTo.author.pronouns === 'string' && ( + + ({sanitizePronouns(replyTo.author.pronouns)}) + + )}