mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-25 19:41:17 -08:00
Feat - misc data styling in user heros (#663)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> This PR proposes styling the misc data (the fields from extended profile that sable does not recognize) in a more robust form, with json formatting, and tapping through the options in order to have a clear visual differentiation between it and anything else. (current view for an example from someone using a different client and thus having different fields) <img width="350" height="701" alt="image" src="https://github.com/user-attachments/assets/996bbcef-f7cf-4bbb-8667-051181d72835" /> (proposed new view, with the badge key selected) <img width="344" height="661" alt="image" src="https://github.com/user-attachments/assets/09cb347d-d287-477b-9562-5854ab09905b" /> (proposed new view when selecting an item) <img width="345" height="564" alt="image" src="https://github.com/user-attachments/assets/e52d18af-ae60-4747-9fd6-eef086373fe1" /> <img width="345" height="653" alt="image" src="https://github.com/user-attachments/assets/9252b65f-d8ea-4926-8793-1b9ddff99b0a" /> (proposed view when there is only one key, and showing it is selected) <img width="346" height="573" alt="image" src="https://github.com/user-attachments/assets/4003f601-ddf4-44e9-b05d-4c07a4015033" /> Fixes # #### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. --> My partner's avocado gasped the implementation as its last breath before rotting away
This commit is contained in:
6 files changed
+143
-39
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
Change Misc. data styling in users profile pages
|
||||
@@ -23,7 +23,7 @@ function UserRoomProfileContextMenu({ state }: { state: UserRoomProfileState })
|
||||
<PopOut
|
||||
anchor={cords}
|
||||
position={position ?? 'Top'}
|
||||
align="Start"
|
||||
align={cords.y > window.innerHeight / 2 ? 'End' : 'Start'}
|
||||
content={
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
|
||||
@@ -433,7 +433,7 @@ export function IgnoredUserAlert() {
|
||||
<CutoutCard style={{ padding: config.space.S200 }} variant="Critical">
|
||||
<SettingTile>
|
||||
<Box direction="Column" gap="200">
|
||||
<Box gap="200" justifyContent="SpaceBetween">
|
||||
<Box gap="200" justifyContent="Center">
|
||||
<Text size="L400">Blocked User</Text>
|
||||
</Box>
|
||||
<Box direction="Column">
|
||||
|
||||
@@ -256,7 +256,9 @@ export function UserModeration({ userId, canKick, canBan, canInvite }: UserModer
|
||||
<Box direction="Column" gap="400">
|
||||
<Box direction="Column" gap="200">
|
||||
<Box grow="Yes" direction="Column" gap="100">
|
||||
<Text size="L400">Moderation</Text>
|
||||
<Text size="L400" align="Center">
|
||||
Moderation
|
||||
</Text>
|
||||
<Input
|
||||
ref={reasonInputRef}
|
||||
placeholder="Reason"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Box, Button, config, Icon, Icons, Scroll, Text } from 'folds';
|
||||
import { Box, Button, config, Icon, Icons, Menu, MenuItem, Scroll, Text, toRem } from 'folds';
|
||||
import { SyntheticEvent, useCallback, useMemo, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAtomValue } from 'jotai';
|
||||
@@ -35,6 +35,7 @@ import { getSettings, settingsAtom } from '$state/settings';
|
||||
import { filterPronounsByLanguage } from '$utils/pronouns';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { TextViewerContent } from '$components/text-viewer';
|
||||
import { CreatorChip } from './CreatorChip';
|
||||
import { UserInviteAlert, UserBanAlert, UserModeration, UserKickAlert } from './UserModeration';
|
||||
import { PowerChip } from './PowerChip';
|
||||
@@ -67,11 +68,8 @@ function UserExtendedSection({
|
||||
htmlReactParserOptions,
|
||||
linkifyOpts,
|
||||
}: Readonly<UserExtendedSectionProps>) {
|
||||
const clamp = (str: any, len: number) => {
|
||||
const stringified = String(str ?? '');
|
||||
return stringified.length > len ? `${stringified.slice(0, len)}...` : stringified;
|
||||
};
|
||||
const [showMore, setShowMore] = useState(false);
|
||||
const [showMisc, setShowMisc] = useState(false);
|
||||
const [miscDataIndex, setMiscDataIndex] = useState(-1);
|
||||
|
||||
const [renderAnimals] = useSetting(settingsAtom, 'renderAnimals');
|
||||
const isCat = profile.isCat === true;
|
||||
@@ -148,6 +146,73 @@ function UserExtendedSection({
|
||||
([key]) => !KNOWN_KEYS.includes(key)
|
||||
);
|
||||
|
||||
function handleMiscSelector(index: number) {
|
||||
setMiscDataIndex(index);
|
||||
setShowMisc(false);
|
||||
}
|
||||
|
||||
const miscSelector = useMemo(() => {
|
||||
if (unknownFields.length === 1 && showMisc) {
|
||||
setShowMisc(false);
|
||||
setMiscDataIndex(miscDataIndex === -1 ? 0 : -1);
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Menu style={{ position: 'absolute', zIndex: '100', transform: `translateY(${toRem(32)})` }}>
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
fill="None"
|
||||
variant="Primary"
|
||||
style={{ justifyContent: 'Center', textAlign: 'center' }}
|
||||
onClick={() => handleMiscSelector(-1)}
|
||||
>
|
||||
<Icon src={Icons.ChevronTop} size="50" />
|
||||
<Text>Show less</Text>
|
||||
</MenuItem>
|
||||
{unknownFields.map(([key], index) => (
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
fill="None"
|
||||
variant="Secondary"
|
||||
style={{ justifyContent: 'Center' }}
|
||||
onClick={() => handleMiscSelector(index)}
|
||||
>
|
||||
<Text>{key}</Text>
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
);
|
||||
}, [miscDataIndex, showMisc, unknownFields]);
|
||||
const miscHeader = useMemo(
|
||||
() => (
|
||||
<Box justifyContent="Center" grow="Yes">
|
||||
<Button
|
||||
variant="Secondary"
|
||||
size="300"
|
||||
fill="None"
|
||||
onClick={() => setShowMisc(!showMisc)}
|
||||
after={miscDataIndex === -1 && <Icon size="50" src={Icons.ChevronBottom} />}
|
||||
style={{
|
||||
padding: '1rem',
|
||||
justifyContent: 'flex-start',
|
||||
width: 'fit-content',
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<Text size="T200" priority="400">
|
||||
{miscDataIndex === -1
|
||||
? `Show Misc. Data (${unknownFields.length} value${unknownFields.length > 1 ? 's' : ''})`
|
||||
: `${unknownFields[miscDataIndex][0]} ${unknownFields.length > 1 ? `(${miscDataIndex + 1}/${unknownFields.length})` : ''}`}
|
||||
</Text>
|
||||
</Button>
|
||||
{showMisc && miscSelector}
|
||||
</Box>
|
||||
),
|
||||
[miscSelector, miscDataIndex, showMisc, unknownFields]
|
||||
);
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="200" style={{ marginBottom: config.space.S100 }}>
|
||||
{(pronouns || localTime) && (
|
||||
@@ -209,39 +274,66 @@ function UserExtendedSection({
|
||||
|
||||
{unknownFields.length > 0 && (
|
||||
<Box direction="Column" gap="100">
|
||||
<Button
|
||||
variant="Secondary"
|
||||
size="300"
|
||||
fill="None"
|
||||
onClick={() => setShowMore(!showMore)}
|
||||
after={<Icon size="50" src={showMore ? Icons.ChevronTop : Icons.ChevronBottom} />}
|
||||
style={{ padding: '1rem', justifyContent: 'flex-start', width: 'fit-content' }}
|
||||
>
|
||||
<Text size="T200" priority="400">
|
||||
{showMore ? 'Show less' : `+ ${unknownFields.length} more info`}
|
||||
</Text>
|
||||
</Button>
|
||||
|
||||
{showMore && (
|
||||
<Box
|
||||
direction="Column"
|
||||
{miscDataIndex === -1 && miscHeader}
|
||||
{miscDataIndex > -1 && (
|
||||
<div
|
||||
style={{
|
||||
padding: config.space.S200,
|
||||
backgroundColor: 'var(--sable-surface-container)',
|
||||
border: '2px solid',
|
||||
backgroundColor: 'var(--sable-bg-container)',
|
||||
borderColor: 'var(--sable-surface-container-line)',
|
||||
borderRadius: config.radii.R400,
|
||||
}}
|
||||
>
|
||||
{unknownFields.map(([key, value]) => (
|
||||
<Box key={key} direction="Column" style={{ marginBottom: config.space.S100 }}>
|
||||
<Text size="T200" priority="400" style={{ letterSpacing: '0.05em' }}>
|
||||
{key}
|
||||
</Text>
|
||||
<Text size="T200" priority="300">
|
||||
{clamp(renderValue(value), 128)}
|
||||
</Text>
|
||||
<Box
|
||||
direction="Row"
|
||||
justifyContent="Center"
|
||||
alignContent="Center"
|
||||
style={{
|
||||
borderRadius: config.radii.R400,
|
||||
}}
|
||||
>
|
||||
{unknownFields.length > 1 && (
|
||||
<Button
|
||||
variant="Secondary"
|
||||
size="300"
|
||||
fill="None"
|
||||
onClick={() =>
|
||||
setMiscDataIndex(
|
||||
miscDataIndex === 0 ? unknownFields.length - 1 : miscDataIndex - 1
|
||||
)
|
||||
}
|
||||
>
|
||||
<Icon src={Icons.ArrowLeft} size="50" />
|
||||
</Button>
|
||||
)}
|
||||
{miscHeader}
|
||||
{unknownFields.length > 1 && (
|
||||
<Button
|
||||
variant="Secondary"
|
||||
size="300"
|
||||
fill="None"
|
||||
onClick={() => setMiscDataIndex((miscDataIndex + 1) % unknownFields.length)}
|
||||
>
|
||||
<Icon src={Icons.ArrowRight} size="50" />
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
<Scroll size="300" direction="Both">
|
||||
<Box
|
||||
direction="Column"
|
||||
style={{
|
||||
padding: config.space.S200,
|
||||
borderRadius: config.radii.R400,
|
||||
maxHeight: toRem(100),
|
||||
}}
|
||||
>
|
||||
<TextViewerContent
|
||||
text={renderValue(unknownFields[miscDataIndex][1])}
|
||||
langName="json"
|
||||
/>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
</Scroll>
|
||||
</div>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
@@ -382,7 +474,7 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
<Box alignItems="Center" gap="100" wrap="Wrap">
|
||||
<Box alignItems="Center" gap="100" wrap="Wrap" justifyContent="Center">
|
||||
{server && <ServerChip server={server} />}
|
||||
<ShareChip userId={userId} />
|
||||
{creator ? <CreatorChip /> : <PowerChip userId={userId} />}
|
||||
|
||||
@@ -282,7 +282,12 @@ export function MembersDrawer({ room, members }: MembersDrawerProps) {
|
||||
const btn = evt.currentTarget as HTMLButtonElement;
|
||||
const userId = btn.getAttribute('data-user-id');
|
||||
if (!userId) return;
|
||||
openUserRoomProfile(room.roomId, space?.roomId, userId, btn.getBoundingClientRect(), 'Left');
|
||||
|
||||
const cords = btn.getBoundingClientRect();
|
||||
// BODGE, dependent on menuItem height staying at toRem(40)
|
||||
cords.y = Math.min(cords.y, window.innerHeight - 42);
|
||||
|
||||
openUserRoomProfile(room.roomId, space?.roomId, userId, cords, 'Left');
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user