mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-24 11:01:17 -08:00
added base setting needed to implement per space sidebar icons
This commit is contained in:
1 parent
604661ef46
commit
b81d2901fc
6 files changed
+176
-6
No files matched your search
@@ -0,0 +1,147 @@
|
||||
import { useState, type MouseEventHandler } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Text,
|
||||
IconButton,
|
||||
Icon,
|
||||
Icons,
|
||||
Scroll,
|
||||
Button,
|
||||
config,
|
||||
Menu,
|
||||
MenuItem,
|
||||
PopOut,
|
||||
type RectCords,
|
||||
} from 'folds';
|
||||
import { Page, PageContent, PageHeader } from '$components/page';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { useRoom } from '$hooks/useRoom';
|
||||
|
||||
import { SequenceCardStyle } from '$features/common-settings/styles.css';
|
||||
import { useShowRoomIcon } from '$hooks/useShowRoomIcon';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import type { ShowRoomIcon } from '$state/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
|
||||
function SelectShowRoomIcon({roomId}: {roomId: string}) {
|
||||
const [menuCords, setMenuCords] = useState<RectCords>();
|
||||
const showRoomIconItems = useShowRoomIcon();
|
||||
const [showRoomIconArray, setShowRoomIconArray] = useSetting(settingsAtom, 'perRoomShowRoomIcon');
|
||||
const showRoomIcon = showRoomIconArray.find(item => item.roomId === roomId )?.display;
|
||||
|
||||
const handleMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setMenuCords(evt.currentTarget.getBoundingClientRect());
|
||||
};
|
||||
|
||||
const handleSelect = (position: ShowRoomIcon) => {
|
||||
const CleanedShowRoomIconArray = showRoomIconArray.filter(item => item.roomId !== roomId );
|
||||
const newShowRoomIconArray = [...CleanedShowRoomIconArray, {roomId, display: position}]
|
||||
setShowRoomIconArray(newShowRoomIconArray);
|
||||
setMenuCords(undefined);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
outlined
|
||||
fill="Soft"
|
||||
radii="300"
|
||||
after={<Icon size="300" src={Icons.ChevronBottom} />}
|
||||
onClick={handleMenu}
|
||||
>
|
||||
<Text size="T300">
|
||||
{showRoomIconItems.find((i) => i.layout === showRoomIcon)?.name ?? showRoomIcon}
|
||||
</Text>
|
||||
</Button>
|
||||
<PopOut
|
||||
anchor={menuCords}
|
||||
offset={5}
|
||||
position="Bottom"
|
||||
align="End"
|
||||
content={
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: () => setMenuCords(undefined),
|
||||
clickOutsideDeactivates: true,
|
||||
isKeyForward: (evt: KeyboardEvent) =>
|
||||
evt.key === 'ArrowDown' || evt.key === 'ArrowRight',
|
||||
isKeyBackward: (evt: KeyboardEvent) =>
|
||||
evt.key === 'ArrowUp' || evt.key === 'ArrowLeft',
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Menu>
|
||||
<Box direction="Column" gap="100" style={{ padding: config.space.S100 }}>
|
||||
{showRoomIconItems.map((item) => (
|
||||
<MenuItem
|
||||
key={item.layout}
|
||||
size="300"
|
||||
variant={showRoomIcon === item.layout ? 'Primary' : 'Surface'}
|
||||
radii="300"
|
||||
onClick={() => handleSelect(item.layout)}
|
||||
>
|
||||
<Text size="T300">{item.name}</Text>
|
||||
</MenuItem>
|
||||
))}
|
||||
</Box>
|
||||
</Menu>
|
||||
</FocusTrap>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
type AppearanceProps = {
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function Appearance({ requestClose }: AppearanceProps) {
|
||||
const room = useRoom();
|
||||
|
||||
return (
|
||||
<Page>
|
||||
<PageHeader outlined={false}>
|
||||
<Box grow="Yes" gap="200">
|
||||
<Box grow="Yes" alignItems="Center" gap="200">
|
||||
<Text size="H3" truncate>
|
||||
Appearance
|
||||
</Text>
|
||||
</Box>
|
||||
<Box shrink="No">
|
||||
<IconButton onClick={requestClose} variant="Surface">
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Box>
|
||||
</PageHeader>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
<Box direction="Column" gap="700">
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Visual Tweaks</Text>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
>
|
||||
<SettingTile
|
||||
title="Show Room Icons In Sidebar"
|
||||
description="When do you want to show the specific room icons in the sidebar within this space?"
|
||||
after={<SelectShowRoomIcon roomId={room.roomId}/>}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
</Box>
|
||||
</PageContent>
|
||||
</Scroll>
|
||||
</Box>
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
@@ -868,7 +868,7 @@ export function Appearance({
|
||||
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Room Icons"
|
||||
title="Show Room Icons In Sidebars"
|
||||
focusId="show-room-icons"
|
||||
description="When do you want to show the specific room icons in the sidebar as opposed to the default room icons?"
|
||||
after={<SelectShowRoomIcon />}
|
||||
|
||||
@@ -17,6 +17,7 @@ import { EmojisStickers } from '$features/common-settings/emojis-stickers';
|
||||
import { Members } from '$features/common-settings/members';
|
||||
import { DeveloperTools } from '$features/common-settings/developer-tools';
|
||||
import { Cosmetics } from '$features/common-settings/cosmetics/Cosmetics';
|
||||
import { Appearance } from '$features/common-settings/appearance/Appearance';
|
||||
import { RoomAbbreviations } from '$features/room-settings/abbreviations/RoomAbbreviations';
|
||||
import { General } from './general';
|
||||
import { Permissions } from './permissions';
|
||||
@@ -67,6 +68,12 @@ const useSpaceSettingsMenuItems = (): SpaceSettingsMenuItem[] =>
|
||||
name: 'Developer Tools',
|
||||
icon: Icons.Terminal,
|
||||
},
|
||||
{
|
||||
page: SpaceSettingsPage.AppearancePage,
|
||||
name: 'Appearance',
|
||||
icon: Icons.Alphabet,
|
||||
activeIcon: Icons.AlphabetUnderline,
|
||||
},
|
||||
],
|
||||
[]
|
||||
);
|
||||
@@ -197,6 +204,9 @@ export function SpaceSettings({ initialPage, requestClose }: SpaceSettingsProps)
|
||||
{activePage === SpaceSettingsPage.AbbreviationsPage && (
|
||||
<RoomAbbreviations isSpace requestClose={handlePageRequestClose} />
|
||||
)}
|
||||
{activePage === SpaceSettingsPage.AppearancePage && (
|
||||
<Appearance requestClose={handlePageRequestClose} />
|
||||
)}
|
||||
</PageRoot>
|
||||
);
|
||||
}
|
||||
@@ -372,7 +372,7 @@ function SpaceHeader({ hideText, mx }: { hideText?: boolean; mx: MatrixClient })
|
||||
</div>
|
||||
{hasBanner && (
|
||||
<>
|
||||
<div className={css.RoomCoverContainer} style={{ height: toRem(curHeight) }}>
|
||||
<Box shrink="No" className={css.RoomCoverContainer} style={{ height: toRem(curHeight) }}>
|
||||
<ClientSideHoverFreeze src={bannerURI} className={css.RoomCover}>
|
||||
<img
|
||||
className={css.RoomCoverImage}
|
||||
@@ -401,7 +401,7 @@ function SpaceHeader({ hideText, mx }: { hideText?: boolean; mx: MatrixClient })
|
||||
topSided
|
||||
/>
|
||||
</ClientSideHoverFreeze>
|
||||
</div>
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
{hasBanner && bannerViewerOpen && (
|
||||
@@ -521,10 +521,15 @@ export function Space() {
|
||||
const [roomSidebarWidth, setRoomSidebarWidth] = useSetting(settingsAtom, 'roomSidebarWidth');
|
||||
const [curWidth, setCurWidth] = useState(roomSidebarWidth);
|
||||
|
||||
const [showRoomIcon] = useSetting(settingsAtom, 'showRoomIcon');
|
||||
const [showRoomIconGeneral] = useSetting(settingsAtom, 'showRoomIcon');
|
||||
|
||||
const [showRoomIconArray] = useSetting(settingsAtom, 'perRoomShowRoomIcon');
|
||||
// oxlint-disable-next-line no-console
|
||||
console.log(showRoomIconArray, space.roomId);
|
||||
|
||||
const showIcons = () => {
|
||||
if (showRoomIcon === ShowRoomIcon.Always) return true;
|
||||
if (showRoomIcon === ShowRoomIcon.Never) return false;
|
||||
if (showRoomIconGeneral === ShowRoomIcon.Always) return true;
|
||||
if (showRoomIconGeneral === ShowRoomIcon.Never) return false;
|
||||
return curWidth < 144;
|
||||
};
|
||||
useEffect(() => {
|
||||
|
||||
@@ -28,6 +28,11 @@ export enum ShowRoomIcon {
|
||||
Smart = 'smart',
|
||||
Never = 'never',
|
||||
}
|
||||
export type PerRoomShowRoomIcon = {
|
||||
roomId: string;
|
||||
display: ShowRoomIcon;
|
||||
};
|
||||
|
||||
export type JumboEmojiSize = 'none' | 'extraSmall' | 'small' | 'normal' | 'large' | 'extraLarge';
|
||||
|
||||
export type ThemeRemoteFavorite = {
|
||||
@@ -160,6 +165,7 @@ export interface Settings {
|
||||
mentionInReplies: boolean;
|
||||
showPersonaSetting: boolean;
|
||||
closeFoldersByDefault: boolean;
|
||||
perRoomShowRoomIcon: PerRoomShowRoomIcon[];
|
||||
showRoomIcon: ShowRoomIcon;
|
||||
showRoomBanners: boolean;
|
||||
roomSidebarWidth: number;
|
||||
@@ -292,6 +298,7 @@ export const defaultSettings: Settings = {
|
||||
mentionInReplies: true,
|
||||
showPersonaSetting: false,
|
||||
closeFoldersByDefault: false,
|
||||
perRoomShowRoomIcon: [],
|
||||
showRoomIcon: ShowRoomIcon.Smart,
|
||||
showRoomBanners: true,
|
||||
roomSidebarWidth: 256,
|
||||
|
||||
@@ -9,6 +9,7 @@ export enum SpaceSettingsPage {
|
||||
// Sable pages
|
||||
CosmeticsPage,
|
||||
AbbreviationsPage,
|
||||
AppearancePage,
|
||||
}
|
||||
|
||||
export type SpaceSettingsState = {
|
||||
|
||||
Reference in new issue
Block a user