feat: route settings and add permalinks
This commit is contained in:
90 files changed
+2171
-281
No files matched your search
@@ -13,6 +13,8 @@
|
||||
"webPushAppID": "moe.sable.app.sygnal"
|
||||
},
|
||||
|
||||
"settingsLinkBaseUrl": "https://app.sable.moe",
|
||||
|
||||
"slidingSync": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { Modal500 } from './Modal500';
|
||||
|
||||
describe('Modal500', () => {
|
||||
it('does not throw when rendered without tabbable children', () => {
|
||||
expect(() =>
|
||||
render(
|
||||
<Modal500 requestClose={vi.fn()}>
|
||||
<div>Empty modal content</div>
|
||||
</Modal500>
|
||||
)
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { ReactNode, useRef } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { Modal, Overlay, OverlayBackdrop, OverlayCenter } from 'folds';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
@@ -8,18 +8,21 @@ type Modal500Props = {
|
||||
children: ReactNode;
|
||||
};
|
||||
export function Modal500({ requestClose, children }: Modal500Props) {
|
||||
const modalRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
return (
|
||||
<Overlay open backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
fallbackFocus: () => modalRef.current ?? document.body,
|
||||
clickOutsideDeactivates: true,
|
||||
onDeactivate: requestClose,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Modal size="500" variant="Background">
|
||||
<Modal ref={modalRef} tabIndex={-1} size="500" variant="Background">
|
||||
{children}
|
||||
</Modal>
|
||||
</FocusTrap>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { MsgType } from '$types/matrix-sdk';
|
||||
import { ClientConfigProvider } from '$hooks/useClientConfig';
|
||||
import { RenderMessageContent } from './RenderMessageContent';
|
||||
|
||||
vi.mock('./url-preview', () => ({
|
||||
UrlPreviewHolder: ({ children }: { children: React.ReactNode }) => (
|
||||
<div data-testid="url-preview-holder">{children}</div>
|
||||
),
|
||||
UrlPreviewCard: ({ url }: { url: string }) => <div data-testid="url-preview-card">{url}</div>,
|
||||
ClientPreview: ({ url }: { url: string }) => <div data-testid="client-preview">{url}</div>,
|
||||
youtubeUrl: () => false,
|
||||
}));
|
||||
|
||||
function renderMessage(body: string, settingsLinkBaseUrl = 'https://app.sable.moe') {
|
||||
return render(
|
||||
<ClientConfigProvider value={{ settingsLinkBaseUrl }}>
|
||||
<RenderMessageContent
|
||||
displayName="Alice"
|
||||
msgType={MsgType.Text}
|
||||
ts={0}
|
||||
getContent={() => ({ body }) as never}
|
||||
urlPreview
|
||||
clientUrlPreview
|
||||
htmlReactParserOptions={{}}
|
||||
linkifyOpts={{}}
|
||||
/>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
describe('RenderMessageContent', () => {
|
||||
it('does not render url previews for settings permalinks', () => {
|
||||
renderMessage('https://app.sable.moe/settings/account/?focus=status');
|
||||
|
||||
expect(screen.queryByTestId('url-preview-holder')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('url-preview-card')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('client-preview')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('still renders url previews for non-settings links', () => {
|
||||
renderMessage('https://example.com');
|
||||
|
||||
expect(screen.getByTestId('url-preview-holder')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('url-preview-card')).toHaveTextContent('https://example.com');
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,7 @@
|
||||
import { memo, useMemo, useCallback } from 'react';
|
||||
import { MsgType } from '$types/matrix-sdk';
|
||||
import { parseSettingsPermalink } from '$features/settings/settingsLink';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { testMatrixTo } from '$plugins/matrix-to';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom, CaptionPosition } from '$state/settings';
|
||||
@@ -80,6 +82,7 @@ function RenderMessageContentInternal({
|
||||
|
||||
const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs');
|
||||
const [captionPosition] = useSetting(settingsAtom, 'captionPosition');
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const captionPositionMap = {
|
||||
[CaptionPosition.Above]: 'column-reverse',
|
||||
[CaptionPosition.Below]: 'column',
|
||||
@@ -101,7 +104,9 @@ function RenderMessageContentInternal({
|
||||
|
||||
const renderUrlsPreview = useCallback(
|
||||
(urls: string[]) => {
|
||||
const filteredUrls = urls.filter((url) => !testMatrixTo(url));
|
||||
const filteredUrls = urls.filter(
|
||||
(url) => !testMatrixTo(url) && !parseSettingsPermalink(settingsLinkBaseUrl, url)
|
||||
);
|
||||
if (filteredUrls.length === 0) return undefined;
|
||||
|
||||
const analyzed = filteredUrls.map((url) => ({
|
||||
@@ -129,7 +134,7 @@ function RenderMessageContentInternal({
|
||||
</UrlPreviewHolder>
|
||||
);
|
||||
},
|
||||
[ts, clientUrlPreview, urlPreview]
|
||||
[ts, clientUrlPreview, settingsLinkBaseUrl, urlPreview]
|
||||
);
|
||||
|
||||
const renderCaption = () => {
|
||||
|
||||
@@ -39,6 +39,7 @@ import { useRoomPermissions } from '$hooks/useRoomPermissions';
|
||||
import { useRoomCreators } from '$hooks/useRoomCreators';
|
||||
import { usePowerLevelsContext } from '$hooks/usePowerLevels';
|
||||
import { MessageEvent } from '$types/matrix/room';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import * as css from './EventHistory.css';
|
||||
|
||||
export type EventHistoryProps = {
|
||||
@@ -50,6 +51,7 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
({ className, room, mEvents, requestClose, ...props }, ref) => {
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const openProfile = useOpenUserRoomProfile();
|
||||
const space = useSpaceOptionally();
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
@@ -72,11 +74,12 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, mEvents[0].getRoomId(), {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
}),
|
||||
[linkifyOpts, mEvents, mx, spoilerClickHandler, useAuthentication]
|
||||
[linkifyOpts, mEvents, mx, settingsLinkBaseUrl, spoilerClickHandler, useAuthentication]
|
||||
);
|
||||
const powerLevels = usePowerLevelsContext();
|
||||
const creators = useRoomCreators(room);
|
||||
|
||||
@@ -27,6 +27,7 @@ import { StateEvent, MessageEvent } from '$types/matrix/room';
|
||||
import { useMentionClickHandler } from '$hooks/useMentionClickHandler';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import * as customHtmlCss from '$styles/CustomHtml.css';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import {
|
||||
MessageBadEncryptedContent,
|
||||
MessageBlockedContent,
|
||||
@@ -120,6 +121,7 @@ export const Reply = as<'div', ReplyProps>(
|
||||
const { color: usernameColor, font: usernameFont } = useSableCosmetics(sender ?? '', room);
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
|
||||
const fallbackBody = isRedacted ? <MessageDeletedContent /> : <MessageFailedContent />;
|
||||
|
||||
@@ -144,17 +146,20 @@ export const Reply = as<'div', ReplyProps>(
|
||||
const replyLinkifyOpts = useMemo(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
render: factoryRenderLinkifyWithMention(
|
||||
settingsLinkBaseUrl,
|
||||
(href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
),
|
||||
mentionClickHandler
|
||||
),
|
||||
}),
|
||||
[mx, room.roomId, mentionClickHandler, nicknames]
|
||||
[mx, room.roomId, mentionClickHandler, nicknames, settingsLinkBaseUrl]
|
||||
);
|
||||
|
||||
if (format === 'org.matrix.custom.html' && formattedBody) {
|
||||
@@ -166,6 +171,7 @@ export const Reply = as<'div', ReplyProps>(
|
||||
.replaceAll(/<\/?(ul|ol|li|blockquote|h[1-6]|pre|div)[^>]*>/gi, '')
|
||||
.replaceAll(/(?:\r\n|\r|\n)/g, ' ');
|
||||
const parserOpts = getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts: replyLinkifyOpts,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
|
||||
@@ -58,11 +58,14 @@ const highlightAnime = keyframes({
|
||||
backgroundColor: color.Primary.Container,
|
||||
},
|
||||
});
|
||||
|
||||
export const messageJumpHighlight = style({
|
||||
animation: `${highlightAnime} 2000ms ease-in-out`,
|
||||
animationIterationCount: 'infinite',
|
||||
});
|
||||
|
||||
const HighlightVariant = styleVariants({
|
||||
true: {
|
||||
animation: `${highlightAnime} 2000ms ease-in-out`,
|
||||
animationIterationCount: 'infinite',
|
||||
},
|
||||
true: [messageJumpHighlight],
|
||||
});
|
||||
|
||||
const NotifyHighlightVariant = styleVariants({
|
||||
|
||||
@@ -29,6 +29,7 @@ export const SequenceCard = as<
|
||||
ContainerColor({ variant }),
|
||||
className
|
||||
)}
|
||||
data-sequence-card="true"
|
||||
data-first-child={firstChild}
|
||||
data-last-child={lastChild}
|
||||
{...props}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { style } from '@vanilla-extract/css';
|
||||
import { config } from 'folds';
|
||||
|
||||
export const settingTileRoot = style({
|
||||
minWidth: 0,
|
||||
});
|
||||
|
||||
export const settingTileTitleRow = style({
|
||||
minWidth: 0,
|
||||
});
|
||||
|
||||
const permalinkActionBase = style({
|
||||
transition:
|
||||
'opacity 150ms ease, transform 150ms ease, color 150ms ease, background-color 150ms ease',
|
||||
});
|
||||
|
||||
export const settingTilePermalinkAction = style([
|
||||
permalinkActionBase,
|
||||
{
|
||||
minWidth: 0,
|
||||
minHeight: 0,
|
||||
width: 'auto',
|
||||
height: 'auto',
|
||||
padding: 0,
|
||||
},
|
||||
]);
|
||||
|
||||
export const settingTilePermalinkActionDesktopHidden = style([
|
||||
permalinkActionBase,
|
||||
{
|
||||
opacity: 0,
|
||||
pointerEvents: 'none',
|
||||
transform: `translateX(${config.space.S100})`,
|
||||
selectors: {
|
||||
[`${settingTileRoot}:hover &`]: {
|
||||
opacity: 1,
|
||||
transform: 'translateX(0)',
|
||||
pointerEvents: 'auto',
|
||||
},
|
||||
[`${settingTileRoot}:focus-within &`]: {
|
||||
opacity: 1,
|
||||
transform: 'translateX(0)',
|
||||
pointerEvents: 'auto',
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
export const settingTilePermalinkActionMobileVisible = style([
|
||||
permalinkActionBase,
|
||||
{
|
||||
opacity: 1,
|
||||
},
|
||||
]);
|
||||
@@ -0,0 +1,97 @@
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { ClientConfigProvider } from '$hooks/useClientConfig';
|
||||
import { ScreenSize, ScreenSizeProvider } from '$hooks/useScreenSize';
|
||||
import { SettingsPermalinkProvider } from '$features/settings/SettingsPermalinkContext';
|
||||
import { SettingTile } from './SettingTile';
|
||||
import {
|
||||
settingTilePermalinkActionDesktopHidden,
|
||||
settingTilePermalinkActionMobileVisible,
|
||||
} from './SettingTile.css';
|
||||
|
||||
const writeText = vi.fn();
|
||||
|
||||
function renderTile(screenSize: ScreenSize, focusId?: string) {
|
||||
return render(
|
||||
<ClientConfigProvider value={{}}>
|
||||
<ScreenSizeProvider value={screenSize}>
|
||||
<SettingsPermalinkProvider
|
||||
value={{ section: 'appearance', baseUrl: 'https://settings.example' }}
|
||||
>
|
||||
<SettingTile focusId={focusId} title="Appearance" />
|
||||
</SettingsPermalinkProvider>
|
||||
</ScreenSizeProvider>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
writeText.mockReset();
|
||||
vi.stubGlobal('navigator', { clipboard: { writeText } } as unknown as Navigator);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('SettingTile', () => {
|
||||
it('copies the real settings permalink when a focus id is present', async () => {
|
||||
writeText.mockResolvedValueOnce(undefined);
|
||||
|
||||
renderTile(ScreenSize.Desktop, 'message-link-preview');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /copy settings permalink/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(writeText).toHaveBeenCalledWith(
|
||||
'https://settings.example/settings/appearance/?focus=message-link-preview'
|
||||
);
|
||||
});
|
||||
expect(screen.getByRole('button', { name: /copied settings permalink/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('keeps the copy state unchanged when clipboard write fails', async () => {
|
||||
writeText.mockRejectedValueOnce(new Error('denied'));
|
||||
|
||||
renderTile(ScreenSize.Desktop, 'message-link-preview');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /copy settings permalink/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(writeText).toHaveBeenCalledWith(
|
||||
'https://settings.example/settings/appearance/?focus=message-link-preview'
|
||||
);
|
||||
});
|
||||
expect(screen.getByRole('button', { name: /copy settings permalink/i })).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /copied settings permalink/i })
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render a copy button without a focus id', () => {
|
||||
renderTile(ScreenSize.Desktop);
|
||||
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /copy settings permalink/i })
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('uses the desktop hidden-until-hover class for the permalink action', () => {
|
||||
renderTile(ScreenSize.Desktop, 'message-link-preview');
|
||||
|
||||
expect(screen.getByText('Appearance').parentElement).toContainElement(
|
||||
screen.getByRole('button', { name: /copy settings permalink/i })
|
||||
);
|
||||
expect(screen.getByRole('button', { name: /copy settings permalink/i })).toHaveClass(
|
||||
settingTilePermalinkActionDesktopHidden
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the mobile always-visible class for the permalink action', () => {
|
||||
renderTile(ScreenSize.Mobile, 'message-link-preview');
|
||||
|
||||
expect(screen.getByRole('button', { name: /copy settings permalink/i })).toHaveClass(
|
||||
settingTilePermalinkActionMobileVisible
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,19 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { Box, Text } from 'folds';
|
||||
import { Box, Icon, IconButton, Icons, Text } from 'folds';
|
||||
import { BreakWord } from '$styles/Text.css';
|
||||
import { buildSettingsPermalink } from '$features/settings/settingsLink';
|
||||
import { copyToClipboard } from '$utils/dom';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
import { useTimeoutToggle } from '$hooks/useTimeoutToggle';
|
||||
import { useSettingsPermalinkContext } from '$features/settings/SettingsPermalinkContext';
|
||||
import { type SettingsSectionId } from '$features/settings/routes';
|
||||
import {
|
||||
settingTilePermalinkAction,
|
||||
settingTilePermalinkActionDesktopHidden,
|
||||
settingTilePermalinkActionMobileVisible,
|
||||
settingTileRoot,
|
||||
settingTileTitleRow,
|
||||
} from './SettingTile.css';
|
||||
|
||||
type SettingTileProps = {
|
||||
focusId?: string;
|
||||
@@ -11,6 +24,42 @@ type SettingTileProps = {
|
||||
after?: ReactNode;
|
||||
children?: ReactNode;
|
||||
};
|
||||
|
||||
function SettingTilePermalinkAction({
|
||||
baseUrl,
|
||||
section,
|
||||
focusId,
|
||||
}: {
|
||||
baseUrl: string;
|
||||
section: SettingsSectionId;
|
||||
focusId: string;
|
||||
}) {
|
||||
const screenSize = useScreenSizeContext();
|
||||
const [copied, setCopied] = useTimeoutToggle();
|
||||
const copyPath = buildSettingsPermalink(baseUrl, section, focusId);
|
||||
|
||||
return (
|
||||
<IconButton
|
||||
aria-label={copied ? 'Copied settings permalink' : 'Copy settings permalink'}
|
||||
className={[
|
||||
settingTilePermalinkAction,
|
||||
screenSize === ScreenSize.Desktop
|
||||
? settingTilePermalinkActionDesktopHidden
|
||||
: settingTilePermalinkActionMobileVisible,
|
||||
].join(' ')}
|
||||
onClick={async () => {
|
||||
if (await copyToClipboard(copyPath)) setCopied();
|
||||
}}
|
||||
size="300"
|
||||
variant="Surface"
|
||||
fill="None"
|
||||
radii="Inherit"
|
||||
>
|
||||
<Icon src={copied ? Icons.Check : Icons.Link} size="50" />
|
||||
</IconButton>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingTile({
|
||||
focusId,
|
||||
className,
|
||||
@@ -20,20 +69,48 @@ export function SettingTile({
|
||||
after,
|
||||
children,
|
||||
}: SettingTileProps) {
|
||||
const settingsPermalink = useSettingsPermalinkContext();
|
||||
const copyAction =
|
||||
settingsPermalink && focusId ? (
|
||||
<SettingTilePermalinkAction
|
||||
baseUrl={settingsPermalink.baseUrl}
|
||||
section={settingsPermalink.section}
|
||||
focusId={focusId}
|
||||
/>
|
||||
) : null;
|
||||
const titleAction = title ? copyAction : null;
|
||||
const trailingCopyAction = title ? null : copyAction;
|
||||
|
||||
const trailing =
|
||||
after || trailingCopyAction ? (
|
||||
<Box shrink="No" alignItems="Center" gap="200">
|
||||
{after}
|
||||
{trailingCopyAction}
|
||||
</Box>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<Box
|
||||
id={focusId}
|
||||
data-settings-focus={focusId}
|
||||
className={className}
|
||||
className={[settingTileRoot, className].filter(Boolean).join(' ')}
|
||||
alignItems="Center"
|
||||
gap="300"
|
||||
>
|
||||
{before && <Box shrink="No">{before}</Box>}
|
||||
<Box grow="Yes" direction="Column" gap="100">
|
||||
{title && (
|
||||
<Text className={BreakWord} size="T300">
|
||||
{title}
|
||||
</Text>
|
||||
<Box
|
||||
data-setting-tile-title-row="true"
|
||||
className={settingTileTitleRow}
|
||||
alignItems="Center"
|
||||
gap="100"
|
||||
>
|
||||
<Text className={BreakWord} size="T300">
|
||||
{title}
|
||||
</Text>
|
||||
{titleAction}
|
||||
</Box>
|
||||
)}
|
||||
{description && (
|
||||
<Text className={BreakWord} size="T200" priority="300">
|
||||
@@ -42,7 +119,7 @@ export function SettingTile({
|
||||
)}
|
||||
{children}
|
||||
</Box>
|
||||
{after && <Box shrink="No">{after}</Box>}
|
||||
{trailing}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import { bytesToSize, getFileTypeIcon } from '$utils/common';
|
||||
import { roomUploadAtomFamily, TUploadItem, TUploadMetadata } from '$state/room/roomInputDrafts';
|
||||
import { useObjectURL } from '$hooks/useObjectURL';
|
||||
import { useMediaConfig } from '$hooks/useMediaConfig';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { UploadCard, UploadCardError, UploadCardProgress } from './UploadCard';
|
||||
import * as css from './UploadCard.css';
|
||||
import { DescriptionEditor } from './UploadDescriptionEditor';
|
||||
@@ -383,14 +384,16 @@ export function UploadCardRenderer({
|
||||
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, roomId, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
}),
|
||||
[linkifyOpts, mx, roomId, spoilerClickHandler, useAuthentication]
|
||||
[linkifyOpts, mx, roomId, settingsLinkBaseUrl, spoilerClickHandler, useAuthentication]
|
||||
);
|
||||
return (
|
||||
<UploadCard
|
||||
|
||||
@@ -34,6 +34,7 @@ import { RenderBody } from '$components/message';
|
||||
import { getSettings, settingsAtom } from '$state/settings';
|
||||
import { filterPronounsByLanguage } from '$utils/pronouns';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { CreatorChip } from './CreatorChip';
|
||||
import { UserInviteAlert, UserBanAlert, UserModeration, UserKickAlert } from './UserModeration';
|
||||
import { PowerChip } from './PowerChip';
|
||||
@@ -315,21 +316,25 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
|
||||
const mentionClickHandler = useCallback((e: SyntheticEvent<HTMLElement>) => {
|
||||
e.preventDefault();
|
||||
}, []);
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
render: factoryRenderLinkifyWithMention(
|
||||
settingsLinkBaseUrl,
|
||||
(href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
),
|
||||
mentionClickHandler
|
||||
),
|
||||
}),
|
||||
[mx, room, mentionClickHandler, nicknames]
|
||||
[mx, room, mentionClickHandler, nicknames, settingsLinkBaseUrl]
|
||||
);
|
||||
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
@@ -337,11 +342,12 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
}),
|
||||
[mx, room, linkifyOpts, useAuthentication, spoilerClickHandler]
|
||||
[mx, room, linkifyOpts, settingsLinkBaseUrl, useAuthentication, spoilerClickHandler]
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
} from '$hooks/useMemberPowerTag';
|
||||
import { useRoomCreators } from '$hooks/useRoomCreators';
|
||||
import { useRoomCreatorsTag } from '$hooks/useRoomCreatorsTag';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { ResultItem } from './useMessageSearch';
|
||||
|
||||
type SearchResultGroupProps = {
|
||||
@@ -90,6 +91,7 @@ export function SearchResultGroup({
|
||||
const theme = useTheme();
|
||||
const accessibleTagColors = useAccessiblePowerTagColors(theme.kind, creatorsTag, powerLevelTags);
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
@@ -97,21 +99,25 @@ export function SearchResultGroup({
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
render: factoryRenderLinkifyWithMention(
|
||||
settingsLinkBaseUrl,
|
||||
(href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
),
|
||||
mentionClickHandler
|
||||
),
|
||||
}),
|
||||
[mx, room, mentionClickHandler, nicknames]
|
||||
[mx, room, mentionClickHandler, nicknames, settingsLinkBaseUrl]
|
||||
);
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
highlightRegex,
|
||||
useAuthentication,
|
||||
@@ -128,6 +134,7 @@ export function SearchResultGroup({
|
||||
spoilerClickHandler,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
settingsLinkBaseUrl,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import { useRoomPermissions } from '$hooks/useRoomPermissions';
|
||||
import { useGetMemberPowerTag } from '$hooks/useMemberPowerTag';
|
||||
import { useRoomNavigate } from '$hooks/useRoomNavigate';
|
||||
import { useMentionClickHandler } from '$hooks/useMentionClickHandler';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler';
|
||||
import { useOpenUserRoomProfile } from '$state/hooks/userRoomProfile';
|
||||
import { useSpaceOptionally } from '$hooks/useSpace';
|
||||
@@ -177,6 +178,7 @@ export function RoomTimeline({
|
||||
const mediaAuthentication = useMediaAuthentication();
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const openUserRoomProfile = useOpenUserRoomProfile();
|
||||
const optionalSpace = useSpaceOptionally();
|
||||
const roomParents = useAtomValue(roomToParentsAtom);
|
||||
@@ -438,22 +440,26 @@ export function RoomTimeline({
|
||||
const linkifyOpts = useMemo(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
render: factoryRenderLinkifyWithMention(
|
||||
settingsLinkBaseUrl,
|
||||
(href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
),
|
||||
mentionClickHandler
|
||||
),
|
||||
}),
|
||||
[mx, room.roomId, mentionClickHandler, nicknames]
|
||||
[mx, room.roomId, mentionClickHandler, nicknames, settingsLinkBaseUrl]
|
||||
);
|
||||
|
||||
const htmlReactParserOptions = useMemo(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication: mediaAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
@@ -470,6 +476,7 @@ export function RoomTimeline({
|
||||
nicknames,
|
||||
mediaAuthentication,
|
||||
spoilerClickHandler,
|
||||
settingsLinkBaseUrl,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { useRoomNavigate } from '$hooks/useRoomNavigate';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { getMemberAvatarMxc, getMemberDisplayName, reactionOrEditEvent } from '$utils/room';
|
||||
@@ -67,6 +68,7 @@ function ThreadPreview({ room, thread, onClick }: ThreadPreviewProps) {
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const { navigateRoom } = useRoomNavigate();
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock');
|
||||
const [dateFormatString] = useSetting(settingsAtom, 'dateFormatString');
|
||||
const [mediaAutoLoad] = useSetting(settingsAtom, 'mediaAutoLoad');
|
||||
@@ -77,29 +79,42 @@ function ThreadPreview({ room, thread, onClick }: ThreadPreviewProps) {
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href: string) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
render: factoryRenderLinkifyWithMention(
|
||||
settingsLinkBaseUrl,
|
||||
(href: string) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
),
|
||||
mentionClickHandler
|
||||
),
|
||||
}),
|
||||
[mx, room.roomId, nicknames, mentionClickHandler]
|
||||
[mx, room.roomId, nicknames, mentionClickHandler, settingsLinkBaseUrl]
|
||||
);
|
||||
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
handleMentionClick: mentionClickHandler,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
}),
|
||||
[mx, room, linkifyOpts, mentionClickHandler, spoilerClickHandler, useAuthentication, nicknames]
|
||||
[
|
||||
mx,
|
||||
room,
|
||||
linkifyOpts,
|
||||
mentionClickHandler,
|
||||
spoilerClickHandler,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
settingsLinkBaseUrl,
|
||||
]
|
||||
);
|
||||
|
||||
const handleJumpClick: MouseEventHandler = useCallback(
|
||||
|
||||
@@ -35,6 +35,7 @@ import { getMxIdLocalPart, toggleReaction } from '$utils/matrix';
|
||||
import { minuteDifference } from '$utils/time';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { MessageLayout, MessageSpacing, settingsAtom } from '$state/settings';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
@@ -367,6 +368,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
|
||||
const pushProcessor = useMemo(() => new PushProcessor(mx), [mx]);
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
|
||||
// Settings
|
||||
@@ -381,29 +383,42 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
render: factoryRenderLinkifyWithMention(
|
||||
settingsLinkBaseUrl,
|
||||
(href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
),
|
||||
mentionClickHandler
|
||||
),
|
||||
}),
|
||||
[mx, room, mentionClickHandler, nicknames]
|
||||
[mx, room, mentionClickHandler, nicknames, settingsLinkBaseUrl]
|
||||
);
|
||||
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
handleMentionClick: mentionClickHandler,
|
||||
nicknames,
|
||||
}),
|
||||
[mx, room, linkifyOpts, spoilerClickHandler, mentionClickHandler, useAuthentication, nicknames]
|
||||
[
|
||||
mx,
|
||||
room,
|
||||
linkifyOpts,
|
||||
spoilerClickHandler,
|
||||
mentionClickHandler,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
settingsLinkBaseUrl,
|
||||
]
|
||||
);
|
||||
|
||||
// Power levels & permissions
|
||||
|
||||
@@ -66,6 +66,7 @@ import { mobileOrTablet } from '$utils/user-agent';
|
||||
import { useComposingCheck } from '$hooks/useComposingCheck';
|
||||
import { floatingEditor } from '$styles/overrides/Composer.css';
|
||||
import { RenderMessageContent } from '$components/RenderMessageContent';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { getReactCustomHtmlParser, LINKIFY_OPTS } from '$plugins/react-custom-html-parser';
|
||||
import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
@@ -348,16 +349,18 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
}, [saveState, onCancel]);
|
||||
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(() => ({ ...LINKIFY_OPTS }), []);
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, mEvent.getRoomId(), {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
}),
|
||||
[linkifyOpts, mEvent, mx, spoilerClickHandler, useAuthentication]
|
||||
[linkifyOpts, mEvent, mx, settingsLinkBaseUrl, spoilerClickHandler, useAuthentication]
|
||||
);
|
||||
const getContent = (() => mEvent.getContent()) as GetContentCallback;
|
||||
const msgType = mEvent.getContent().msgtype;
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
import { GetContentCallback, MessageEvent, StateEvent } from '$types/matrix/room';
|
||||
import { useMentionClickHandler } from '$hooks/useMentionClickHandler';
|
||||
import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import {
|
||||
factoryRenderLinkifyWithMention,
|
||||
getReactCustomHtmlParser,
|
||||
@@ -332,26 +333,31 @@ export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
|
||||
});
|
||||
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
render: factoryRenderLinkifyWithMention(
|
||||
settingsLinkBaseUrl,
|
||||
(href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
),
|
||||
mentionClickHandler
|
||||
),
|
||||
}),
|
||||
[mx, room, mentionClickHandler, nicknames]
|
||||
[mx, room, mentionClickHandler, nicknames, settingsLinkBaseUrl]
|
||||
);
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
@@ -366,6 +372,7 @@ export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
|
||||
spoilerClickHandler,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
settingsLinkBaseUrl,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@ import { SettingsSectionPage } from '../SettingsSectionPage';
|
||||
import { PerMessageProfileOverview } from './PerMessageProfileOverview';
|
||||
|
||||
type PerMessageProfilePageProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
|
||||
export function PerMessageProfilePage({ requestClose }: PerMessageProfilePageProps) {
|
||||
export function PerMessageProfilePage({ requestBack, requestClose }: PerMessageProfilePageProps) {
|
||||
return (
|
||||
<SettingsSectionPage title="Persona" requestClose={requestClose}>
|
||||
<SettingsSectionPage title="Persona" requestBack={requestBack} requestClose={requestClose}>
|
||||
<PageNavContent>
|
||||
<Box
|
||||
grow="Yes"
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { ClientConfigProvider } from '$hooks/useClientConfig';
|
||||
import { ScreenSize, ScreenSizeProvider } from '$hooks/useScreenSize';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { Settings } from './Settings';
|
||||
|
||||
const writeText = vi.fn();
|
||||
|
||||
const { mockMatrixClient, mockProfile } = vi.hoisted(() => ({
|
||||
mockMatrixClient: { getUserId: () => '@alice:server' },
|
||||
mockProfile: { displayName: 'Alice', avatarUrl: undefined },
|
||||
}));
|
||||
|
||||
let settingsLinkBaseUrlOverride: string | undefined;
|
||||
|
||||
vi.mock('$hooks/useMatrixClient', () => ({
|
||||
useMatrixClient: () => mockMatrixClient,
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useUserProfile', () => ({
|
||||
useUserProfile: () => mockProfile,
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useMediaAuthentication', () => ({
|
||||
useMediaAuthentication: () => false,
|
||||
}));
|
||||
|
||||
vi.mock('$state/hooks/settings', () => ({
|
||||
useSetting: (_atom: unknown, key: string) => {
|
||||
if (key === 'settingsLinkBaseUrlOverride') {
|
||||
return [settingsLinkBaseUrlOverride, vi.fn()] as const;
|
||||
}
|
||||
|
||||
return [true, vi.fn()] as const;
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('$state/settings', () => ({
|
||||
settingsAtom: {},
|
||||
}));
|
||||
|
||||
vi.mock('./useSettingsFocus', () => ({
|
||||
useSettingsFocus: () => {},
|
||||
}));
|
||||
|
||||
vi.mock('./general', () => ({
|
||||
General: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
General
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./account', () => ({
|
||||
Account: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
Account
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./Persona/ProfilesPage', () => ({
|
||||
PerMessageProfilePage: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
Persona
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./cosmetics/Cosmetics', () => ({
|
||||
Cosmetics: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<div>
|
||||
<SettingTile focusId="message-link-preview" title="Appearance" />
|
||||
<button type="button" onClick={requestClose}>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./notifications', () => ({
|
||||
Notifications: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
Notifications
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./devices', () => ({
|
||||
Devices: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
Devices
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./emojis-stickers', () => ({
|
||||
EmojisStickers: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
Emojis
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./developer-tools', () => ({
|
||||
DeveloperTools: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
Developer Tools
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./experimental/Experimental', () => ({
|
||||
Experimental: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
Experimental
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./about', () => ({
|
||||
About: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
About
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./keyboard-shortcuts', () => ({
|
||||
KeyboardShortcuts: ({ requestClose }: { requestClose: () => void }) => (
|
||||
<button type="button" onClick={requestClose}>
|
||||
Keyboard Shortcuts
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
writeText.mockReset();
|
||||
settingsLinkBaseUrlOverride = undefined;
|
||||
vi.stubGlobal('location', { origin: 'https://app.example' } as Location);
|
||||
vi.stubGlobal('navigator', { clipboard: { writeText } } as unknown as Navigator);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('Settings', () => {
|
||||
it('uses the configured settings link base URL for copied settings permalinks', async () => {
|
||||
writeText.mockResolvedValueOnce(undefined);
|
||||
|
||||
render(
|
||||
<ClientConfigProvider value={{ settingsLinkBaseUrl: 'https://config.example' }}>
|
||||
<ScreenSizeProvider value={ScreenSize.Desktop}>
|
||||
<Settings activeSection="appearance" requestClose={vi.fn()} />
|
||||
</ScreenSizeProvider>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /copy settings permalink/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(writeText).toHaveBeenCalledWith(
|
||||
'https://config.example/settings/appearance/?focus=message-link-preview'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('prefers the client-side override over the configured settings link base URL', async () => {
|
||||
writeText.mockResolvedValueOnce(undefined);
|
||||
settingsLinkBaseUrlOverride = 'https://override.example/';
|
||||
|
||||
render(
|
||||
<ClientConfigProvider value={{ settingsLinkBaseUrl: 'https://config.example' }}>
|
||||
<ScreenSizeProvider value={ScreenSize.Desktop}>
|
||||
<Settings activeSection="appearance" requestClose={vi.fn()} />
|
||||
</ScreenSizeProvider>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /copy settings permalink/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(writeText).toHaveBeenCalledWith(
|
||||
'https://override.example/settings/appearance/?focus=message-link-preview'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -40,7 +40,10 @@ import { KeyboardShortcuts } from './keyboard-shortcuts';
|
||||
import { Notifications } from './notifications';
|
||||
import { PerMessageProfilePage } from './Persona/ProfilesPage';
|
||||
import { settingsSections, type SettingsSectionId } from './routes';
|
||||
import { settingsHeader } from './styles.css';
|
||||
import { useSettingsFocus } from './useSettingsFocus';
|
||||
import { SettingsPermalinkProvider } from './SettingsPermalinkContext';
|
||||
import { useSettingsLinkBaseUrl } from './useSettingsLinkBaseUrl';
|
||||
|
||||
export enum SettingsPages {
|
||||
GeneralPage,
|
||||
@@ -110,7 +113,7 @@ const settingsSectionIdToPage: Record<SettingsSectionId, SettingsPages> = {
|
||||
|
||||
const settingsSectionComponents: Record<
|
||||
SettingsSectionId,
|
||||
(props: { requestClose: () => void }) => JSX.Element
|
||||
(props: { requestBack?: () => void; requestClose: () => void }) => JSX.Element
|
||||
> = {
|
||||
general: General,
|
||||
account: Account,
|
||||
@@ -128,25 +131,29 @@ const settingsSectionComponents: Record<
|
||||
type ControlledSettingsProps = {
|
||||
activeSection?: SettingsSectionId | null;
|
||||
onSelectSection?: (section: SettingsSectionId) => void;
|
||||
onBack?: () => void;
|
||||
requestClose: () => void;
|
||||
initialPage?: SettingsPages;
|
||||
};
|
||||
|
||||
function SettingsSectionViewport({
|
||||
section,
|
||||
requestBack,
|
||||
requestClose,
|
||||
}: {
|
||||
section: SettingsSectionId;
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
}) {
|
||||
useSettingsFocus();
|
||||
const Section = settingsSectionComponents[section];
|
||||
return <Section requestClose={requestClose} />;
|
||||
return <Section requestBack={requestBack} requestClose={requestClose} />;
|
||||
}
|
||||
|
||||
export function Settings({
|
||||
activeSection,
|
||||
onSelectSection,
|
||||
onBack,
|
||||
requestClose,
|
||||
initialPage,
|
||||
}: ControlledSettingsProps) {
|
||||
@@ -160,6 +167,7 @@ export function Settings({
|
||||
: undefined;
|
||||
|
||||
const [showPersona] = useSetting(settingsAtom, 'showPersonaSetting');
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const screenSize = useScreenSizeContext();
|
||||
const isControlled = activeSection !== undefined;
|
||||
|
||||
@@ -220,12 +228,30 @@ export function Settings({
|
||||
requestClose();
|
||||
};
|
||||
|
||||
const handleRequestBack = () => {
|
||||
if (isControlled) {
|
||||
onBack?.();
|
||||
return;
|
||||
}
|
||||
|
||||
if (screenSize === ScreenSize.Mobile) {
|
||||
setLegacyActivePage(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
setLegacyActivePage(SettingsPages.GeneralPage);
|
||||
};
|
||||
|
||||
const shouldShowSectionBack =
|
||||
visibleSection !== null && (screenSize === ScreenSize.Mobile || visibleSection !== 'general');
|
||||
const sectionRequestBack = shouldShowSectionBack ? handleRequestBack : undefined;
|
||||
|
||||
return (
|
||||
<PageRoot
|
||||
nav={
|
||||
screenSize === ScreenSize.Mobile && visibleSection !== null ? undefined : (
|
||||
<PageNav size="300">
|
||||
<PageNavHeader outlined={false}>
|
||||
<PageNavHeader className={settingsHeader}>
|
||||
<Box grow="Yes" gap="200">
|
||||
<Avatar size="200" radii="300">
|
||||
<UserAvatar
|
||||
@@ -239,7 +265,7 @@ export function Settings({
|
||||
</Text>
|
||||
</Box>
|
||||
<Box shrink="No">
|
||||
{screenSize === ScreenSize.Mobile && (
|
||||
{visibleSection === null && (
|
||||
<IconButton
|
||||
aria-label="Close settings"
|
||||
onClick={handleRequestClose}
|
||||
@@ -264,7 +290,11 @@ export function Settings({
|
||||
radii="400"
|
||||
aria-pressed={visibleSection === item.id}
|
||||
before={
|
||||
<Icon src={currentIcon} size="100" filled={visibleSection === item.id} />
|
||||
<Icon
|
||||
src={currentIcon}
|
||||
size={screenSize === ScreenSize.Mobile ? '200' : '100'}
|
||||
filled={visibleSection === item.id}
|
||||
/>
|
||||
}
|
||||
onClick={() => handleSelectSection(item.id)}
|
||||
>
|
||||
@@ -273,7 +303,7 @@ export function Settings({
|
||||
fontWeight:
|
||||
visibleSection === item.id ? config.fontWeight.W600 : undefined,
|
||||
}}
|
||||
size="T300"
|
||||
size={screenSize === ScreenSize.Mobile ? 'T400' : 'T300'}
|
||||
truncate
|
||||
>
|
||||
{item.name}
|
||||
@@ -322,7 +352,15 @@ export function Settings({
|
||||
}
|
||||
>
|
||||
{visibleSection && (
|
||||
<SettingsSectionViewport section={visibleSection} requestClose={handleRequestClose} />
|
||||
<SettingsPermalinkProvider
|
||||
value={{ section: visibleSection, baseUrl: settingsLinkBaseUrl }}
|
||||
>
|
||||
<SettingsSectionViewport
|
||||
section={visibleSection}
|
||||
requestBack={sectionRequestBack}
|
||||
requestClose={handleRequestClose}
|
||||
/>
|
||||
</SettingsPermalinkProvider>
|
||||
)}
|
||||
</PageRoot>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { createContext, useContext } from 'react';
|
||||
import { type SettingsSectionId } from './routes';
|
||||
|
||||
type SettingsPermalinkContextValue = {
|
||||
section: SettingsSectionId;
|
||||
baseUrl: string;
|
||||
};
|
||||
|
||||
const SettingsPermalinkContext = createContext<SettingsPermalinkContextValue | null>(null);
|
||||
|
||||
export const SettingsPermalinkProvider = SettingsPermalinkContext.Provider;
|
||||
|
||||
export const useSettingsPermalinkContext = (): SettingsPermalinkContextValue | null =>
|
||||
useContext(SettingsPermalinkContext);
|
||||
|
||||
export type { SettingsPermalinkContextValue };
|
||||
@@ -10,28 +10,56 @@ import {
|
||||
useNavigationType,
|
||||
} from 'react-router-dom';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { Text } from 'folds';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { ClientConfigProvider } from '$hooks/useClientConfig';
|
||||
import { ClientLayout } from '$pages/client';
|
||||
import { ClientRouteOutlet } from '$pages/client/ClientRouteOutlet';
|
||||
import { ScreenSize, ScreenSizeProvider } from '$hooks/useScreenSize';
|
||||
import * as pageCss from '$components/page/style.css';
|
||||
import { messageJumpHighlight } from '$components/message/layout/layout.css';
|
||||
import { getHomePath, getSettingsPath } from '$pages/pathUtils';
|
||||
import { SETTINGS_PATH } from '$pages/paths';
|
||||
import { SettingsRoute } from './SettingsRoute';
|
||||
import { SettingsShallowRouteRenderer } from './SettingsShallowRouteRenderer';
|
||||
import { SettingsSectionPage } from './SettingsSectionPage';
|
||||
import { focusedSettingTile } from './styles.css';
|
||||
import * as settingsCss from './styles.css';
|
||||
import { useOpenSettings } from './useOpenSettings';
|
||||
import { useSettingsFocus } from './useSettingsFocus';
|
||||
|
||||
type RouterInitialEntry =
|
||||
| string
|
||||
| {
|
||||
pathname: string;
|
||||
search?: string;
|
||||
hash?: string;
|
||||
state?: unknown;
|
||||
key?: string;
|
||||
};
|
||||
|
||||
const { mockMatrixClient, mockProfile, mockUseSetting, createSectionMock } = vi.hoisted(() => {
|
||||
const mockSettingsHook = vi.fn(() => [true, vi.fn()] as const);
|
||||
|
||||
const createMockSection = (title: string) =>
|
||||
function MockSection({ requestClose }: { requestClose: () => void }) {
|
||||
function MockSection({
|
||||
requestBack,
|
||||
requestClose,
|
||||
}: {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div>
|
||||
<h1>{title}</h1>
|
||||
{requestBack && (
|
||||
<button type="button" onClick={requestBack}>
|
||||
Back
|
||||
</button>
|
||||
)}
|
||||
<button type="button" onClick={requestClose}>
|
||||
Back
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
@@ -66,7 +94,28 @@ vi.mock('$components/Modal500', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('./general', () => ({
|
||||
General: createSectionMock('General section'),
|
||||
General: ({
|
||||
requestBack,
|
||||
requestClose,
|
||||
}: {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
}) => (
|
||||
<div>
|
||||
<h1>General section</h1>
|
||||
<SequenceCard variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile focusId="message-layout">Message Layout</SettingTile>
|
||||
</SequenceCard>
|
||||
{requestBack && (
|
||||
<button type="button" onClick={requestBack}>
|
||||
Back
|
||||
</button>
|
||||
)}
|
||||
<button type="button" onClick={requestClose}>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('./account', () => ({
|
||||
@@ -114,7 +163,9 @@ function FocusFixture() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SettingTile focusId="message-link-preview">focus target</SettingTile>
|
||||
<SequenceCard variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile focusId="message-link-preview">focus target</SettingTile>
|
||||
</SequenceCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -167,22 +218,24 @@ function OpenSettingsHomePage() {
|
||||
|
||||
function renderClientShell(
|
||||
screenSize: ScreenSize,
|
||||
options?: { initialEntries?: string[]; initialIndex?: number }
|
||||
options?: { initialEntries?: RouterInitialEntry[]; initialIndex?: number }
|
||||
) {
|
||||
const initialEntries = options?.initialEntries ?? [getHomePath()];
|
||||
return render(
|
||||
<MemoryRouter initialEntries={initialEntries} initialIndex={options?.initialIndex}>
|
||||
<ScreenSizeProvider value={screenSize}>
|
||||
<LocationProbe />
|
||||
<Routes>
|
||||
<Route element={<ClientRouteOutlet />}>
|
||||
<Route path={getHomePath()} element={<HomePage />} />
|
||||
<Route path={SETTINGS_PATH} element={<SettingsRoute />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<SettingsShallowRouteRenderer />
|
||||
</ScreenSizeProvider>
|
||||
</MemoryRouter>
|
||||
<ClientConfigProvider value={{}}>
|
||||
<MemoryRouter initialEntries={initialEntries} initialIndex={options?.initialIndex}>
|
||||
<ScreenSizeProvider value={screenSize}>
|
||||
<LocationProbe />
|
||||
<Routes>
|
||||
<Route element={<ClientRouteOutlet />}>
|
||||
<Route path={getHomePath()} element={<HomePage />} />
|
||||
<Route path={SETTINGS_PATH} element={<SettingsRoute />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<SettingsShallowRouteRenderer />
|
||||
</ScreenSizeProvider>
|
||||
</MemoryRouter>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -198,53 +251,92 @@ function SidebarSettingsShortcut() {
|
||||
|
||||
function renderClientShellWithOpenSettings(
|
||||
screenSize: ScreenSize,
|
||||
options?: { initialEntries?: string[]; initialIndex?: number }
|
||||
options?: { initialEntries?: RouterInitialEntry[]; initialIndex?: number }
|
||||
) {
|
||||
const initialEntries = options?.initialEntries ?? [getHomePath()];
|
||||
return render(
|
||||
<MemoryRouter initialEntries={initialEntries} initialIndex={options?.initialIndex}>
|
||||
<ScreenSizeProvider value={screenSize}>
|
||||
<LocationProbe />
|
||||
<SidebarSettingsShortcut />
|
||||
<Routes>
|
||||
<Route element={<ClientRouteOutlet />}>
|
||||
<Route path={getHomePath()} element={<OpenSettingsHomePage />} />
|
||||
<Route path={SETTINGS_PATH} element={<SettingsRoute />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<SettingsShallowRouteRenderer />
|
||||
</ScreenSizeProvider>
|
||||
</MemoryRouter>
|
||||
<ClientConfigProvider value={{}}>
|
||||
<MemoryRouter initialEntries={initialEntries} initialIndex={options?.initialIndex}>
|
||||
<ScreenSizeProvider value={screenSize}>
|
||||
<LocationProbe />
|
||||
<SidebarSettingsShortcut />
|
||||
<Routes>
|
||||
<Route element={<ClientRouteOutlet />}>
|
||||
<Route path={getHomePath()} element={<OpenSettingsHomePage />} />
|
||||
<Route path={SETTINGS_PATH} element={<SettingsRoute />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<SettingsShallowRouteRenderer />
|
||||
</ScreenSizeProvider>
|
||||
</MemoryRouter>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function renderClientLayoutShell(
|
||||
screenSize: ScreenSize,
|
||||
options?: { initialEntries?: RouterInitialEntry[]; initialIndex?: number }
|
||||
) {
|
||||
const initialEntries = options?.initialEntries ?? [getHomePath()];
|
||||
return render(
|
||||
<ClientConfigProvider value={{}}>
|
||||
<MemoryRouter initialEntries={initialEntries} initialIndex={options?.initialIndex}>
|
||||
<ScreenSizeProvider value={screenSize}>
|
||||
<LocationProbe />
|
||||
<Routes>
|
||||
<Route
|
||||
element={
|
||||
<ClientLayout nav={<div>App sidebar</div>}>
|
||||
<ClientRouteOutlet />
|
||||
</ClientLayout>
|
||||
}
|
||||
>
|
||||
<Route path={getHomePath()} element={<HomePage />} />
|
||||
<Route path={SETTINGS_PATH} element={<SettingsRoute />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<SettingsShallowRouteRenderer />
|
||||
</ScreenSizeProvider>
|
||||
</MemoryRouter>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function renderSettingsRoute(
|
||||
path: string,
|
||||
screenSize: ScreenSize,
|
||||
options?: { initialEntries?: string[]; initialIndex?: number }
|
||||
options?: { initialEntries?: RouterInitialEntry[]; initialIndex?: number }
|
||||
) {
|
||||
const initialEntries = options?.initialEntries ?? [path];
|
||||
return render(
|
||||
<MemoryRouter initialEntries={initialEntries} initialIndex={options?.initialIndex}>
|
||||
<ScreenSizeProvider value={screenSize}>
|
||||
<LocationProbe />
|
||||
<Routes>
|
||||
<Route path={SETTINGS_PATH} element={<SettingsRoute />} />
|
||||
</Routes>
|
||||
</ScreenSizeProvider>
|
||||
</MemoryRouter>
|
||||
<ClientConfigProvider value={{}}>
|
||||
<MemoryRouter initialEntries={initialEntries} initialIndex={options?.initialIndex}>
|
||||
<ScreenSizeProvider value={screenSize}>
|
||||
<LocationProbe />
|
||||
<Routes>
|
||||
<Route path={SETTINGS_PATH} element={<SettingsRoute />} />
|
||||
</Routes>
|
||||
</ScreenSizeProvider>
|
||||
</MemoryRouter>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
describe('SettingsSectionPage', () => {
|
||||
it('shows a back affordance on mobile section pages', () => {
|
||||
it('reuses the message jump highlight class without adding a separate radius override', () => {
|
||||
expect(focusedSettingTile).toBe(messageJumpHighlight);
|
||||
});
|
||||
|
||||
it('shows back on the left and close on the right for mobile section pages', () => {
|
||||
render(
|
||||
<ScreenSizeProvider value={ScreenSize.Mobile}>
|
||||
<SettingsSectionPage title="Devices" requestClose={vi.fn()} />
|
||||
<SettingsSectionPage title="Devices" requestBack={vi.fn()} requestClose={vi.fn()} />
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('button')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getAllByRole('button').map((button) => button.getAttribute('aria-label'))
|
||||
).toEqual(['Back', 'Close']);
|
||||
});
|
||||
|
||||
it('supports custom title semantics and close label', () => {
|
||||
@@ -254,14 +346,51 @@ describe('SettingsSectionPage', () => {
|
||||
title="Keyboard Shortcuts"
|
||||
titleAs="h1"
|
||||
actionLabel="Close keyboard shortcuts"
|
||||
requestBack={vi.fn()}
|
||||
requestClose={vi.fn()}
|
||||
/>
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Keyboard Shortcuts');
|
||||
expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Close keyboard shortcuts' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('uses the default outlined page header treatment', () => {
|
||||
render(
|
||||
<ScreenSizeProvider value={ScreenSize.Desktop}>
|
||||
<SettingsSectionPage title="Devices" requestBack={vi.fn()} requestClose={vi.fn()} />
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Devices').closest('header')).toHaveClass(pageCss.PageHeader({}));
|
||||
});
|
||||
|
||||
it('matches the main settings header title size', () => {
|
||||
const rootRender = renderSettingsRoute('/settings', ScreenSize.Mobile);
|
||||
const mainHeaderClassName = screen.getByText('Settings').className;
|
||||
|
||||
rootRender.unmount();
|
||||
|
||||
render(
|
||||
<ScreenSizeProvider value={ScreenSize.Mobile}>
|
||||
<SettingsSectionPage title="Devices" requestBack={vi.fn()} requestClose={vi.fn()} />
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Devices').className).toBe(mainHeaderClassName);
|
||||
});
|
||||
|
||||
it('uses settings header spacing that matches the main settings shell', () => {
|
||||
render(
|
||||
<ScreenSizeProvider value={ScreenSize.Mobile}>
|
||||
<SettingsSectionPage title="Devices" requestBack={vi.fn()} requestClose={vi.fn()} />
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Devices').closest('header')).toHaveClass(settingsCss.settingsHeader);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SettingsRoute', () => {
|
||||
@@ -273,6 +402,27 @@ describe('SettingsRoute', () => {
|
||||
expect(screen.queryByRole('heading', { name: 'General section' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('uses the default outlined nav header treatment for the settings menu', () => {
|
||||
renderSettingsRoute('/settings', ScreenSize.Mobile);
|
||||
|
||||
expect(screen.getByText('Settings').closest('header')).toHaveClass(pageCss.PageNavHeader({}));
|
||||
});
|
||||
|
||||
it('uses larger nav labels on mobile settings', () => {
|
||||
const referenceRender = render(
|
||||
<Text size="T400" truncate>
|
||||
Reference
|
||||
</Text>
|
||||
);
|
||||
const mobileClassName = screen.getByText('Reference').className;
|
||||
|
||||
referenceRender.unmount();
|
||||
|
||||
renderSettingsRoute('/settings', ScreenSize.Mobile);
|
||||
|
||||
expect(screen.getByText('Notifications').className).toBe(mobileClassName);
|
||||
});
|
||||
|
||||
it('redirects desktop /settings to /settings/general', async () => {
|
||||
renderSettingsRoute('/settings', ScreenSize.Desktop);
|
||||
|
||||
@@ -291,19 +441,80 @@ describe('SettingsRoute', () => {
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent(getSettingsPath('general'))
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Back' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Close' }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent(getHomePath())
|
||||
);
|
||||
});
|
||||
|
||||
it('closes to the stored background route instead of stepping through prior settings entries', async () => {
|
||||
const user = userEvent.setup();
|
||||
const backgroundLocation = {
|
||||
pathname: getHomePath(),
|
||||
search: '',
|
||||
hash: '',
|
||||
state: null,
|
||||
key: 'home',
|
||||
};
|
||||
|
||||
renderSettingsRoute(getSettingsPath('devices'), ScreenSize.Desktop, {
|
||||
initialEntries: [
|
||||
getHomePath(),
|
||||
{
|
||||
pathname: getSettingsPath('notifications'),
|
||||
state: { backgroundLocation },
|
||||
key: 'settings-notifications',
|
||||
},
|
||||
{
|
||||
pathname: getSettingsPath('devices'),
|
||||
state: { backgroundLocation },
|
||||
key: 'settings-devices',
|
||||
},
|
||||
],
|
||||
initialIndex: 2,
|
||||
});
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Close' }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent(getHomePath())
|
||||
);
|
||||
expect(screen.getByTestId('location-probe')).not.toHaveTextContent(
|
||||
getSettingsPath('notifications')
|
||||
);
|
||||
});
|
||||
|
||||
it('renders the requested section at /settings/devices', () => {
|
||||
renderSettingsRoute('/settings/devices', ScreenSize.Mobile);
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Devices section' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('focuses and highlights a real general setting tile from the URL', async () => {
|
||||
vi.useFakeTimers();
|
||||
|
||||
try {
|
||||
renderSettingsRoute('/settings/general?focus=message-layout', ScreenSize.Mobile);
|
||||
|
||||
const target = document.querySelector('[data-settings-focus="message-layout"]');
|
||||
const highlightTarget = target?.parentElement;
|
||||
|
||||
expect(target).not.toHaveClass(focusedSettingTile);
|
||||
expect(highlightTarget).toHaveClass(focusedSettingTile);
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent('?focus=message-layout');
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(3000);
|
||||
});
|
||||
|
||||
expect(highlightTarget).not.toHaveClass(focusedSettingTile);
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent('/settings/general');
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it('redirects invalid sections back to /settings', async () => {
|
||||
renderSettingsRoute('/settings/not-a-real-section', ScreenSize.Mobile);
|
||||
|
||||
@@ -326,6 +537,18 @@ describe('SettingsRoute', () => {
|
||||
expect(screen.getByText('Settings')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('falls back to /home when a direct section entry is closed', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
renderSettingsRoute('/settings/devices', ScreenSize.Mobile);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Close' }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent(getHomePath())
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to /home when the root settings page is closed from a direct entry', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
@@ -446,7 +669,7 @@ describe('Settings shallow route shell', () => {
|
||||
expect(screen.getByRole('heading', { name: 'Devices section' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('closes a desktop shallow settings flow in one step after switching sections', async () => {
|
||||
it('returns to general settings when desktop section back is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
renderClientShell(ScreenSize.Desktop);
|
||||
@@ -455,6 +678,20 @@ describe('Settings shallow route shell', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Devices' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Back' }));
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Home route' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'General section' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('heading', { name: 'Devices section' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('closes a desktop shallow settings flow in one step after switching sections', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
renderClientShell(ScreenSize.Desktop);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Open settings' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Devices' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Close' }));
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Home route' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('heading', { name: 'Devices section' })).not.toBeInTheDocument();
|
||||
expect(
|
||||
@@ -471,6 +708,15 @@ describe('Settings shallow route shell', () => {
|
||||
expect(screen.queryByRole('heading', { name: 'Home route' })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Devices section' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides the client sidebar when desktop settings renders as a full page', () => {
|
||||
renderClientLayoutShell(ScreenSize.Desktop, {
|
||||
initialEntries: [getSettingsPath('devices')],
|
||||
});
|
||||
|
||||
expect(screen.queryByText('App sidebar')).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Devices section' })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('useSettingsFocus', () => {
|
||||
@@ -488,20 +734,24 @@ describe('useSettingsFocus', () => {
|
||||
);
|
||||
|
||||
const target = document.querySelector('[data-settings-focus="message-link-preview"]');
|
||||
expect(target).toHaveClass(focusedSettingTile);
|
||||
const highlightTarget = target?.parentElement;
|
||||
expect(target).not.toHaveClass(focusedSettingTile);
|
||||
expect(highlightTarget).toHaveClass(focusedSettingTile);
|
||||
expect(highlightTarget).toHaveClass(messageJumpHighlight);
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent('?focus=message-link-preview');
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(2999);
|
||||
});
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent('?focus=message-link-preview');
|
||||
expect(target).toHaveClass(focusedSettingTile);
|
||||
expect(highlightTarget).toHaveClass(focusedSettingTile);
|
||||
expect(highlightTarget).toHaveClass(messageJumpHighlight);
|
||||
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
});
|
||||
expect(screen.getByTestId('location-probe')).toHaveTextContent('/settings/appearance');
|
||||
expect(target).not.toHaveClass(focusedSettingTile);
|
||||
expect(highlightTarget).not.toHaveClass(focusedSettingTile);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
import { getHomePath, getSettingsPath } from '$pages/pathUtils';
|
||||
import { getSettingsPath } from '$pages/pathUtils';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { getSettingsCloseTarget, type SettingsRouteState } from './navigation';
|
||||
import { Settings } from './Settings';
|
||||
import { isSettingsSectionId, type SettingsSectionId } from './routes';
|
||||
|
||||
type SettingsRouteState = {
|
||||
backgroundLocation?: unknown;
|
||||
redirectedFromDesktopRoot?: boolean;
|
||||
};
|
||||
|
||||
function resolveSettingsSection(
|
||||
section: string | undefined,
|
||||
screenSize: ScreenSize,
|
||||
@@ -41,6 +37,13 @@ export function SettingsRoute() {
|
||||
const routeState = location.state as SettingsRouteState | null;
|
||||
const shallowBackgroundState =
|
||||
screenSize !== ScreenSize.Mobile && Boolean(routeState?.backgroundLocation);
|
||||
const browserHistoryIndex =
|
||||
typeof window !== 'undefined' && typeof window.history.state?.idx === 'number'
|
||||
? window.history.state.idx
|
||||
: null;
|
||||
const hasPreviousEntry =
|
||||
(typeof browserHistoryIndex === 'number' && browserHistoryIndex > 0) ||
|
||||
location.key !== 'default';
|
||||
|
||||
const activeSection = resolveSettingsSection(section, screenSize, showPersona);
|
||||
const shouldRedirectToGeneral = section === undefined && screenSize !== ScreenSize.Mobile;
|
||||
@@ -62,23 +65,38 @@ export function SettingsRoute() {
|
||||
|
||||
if (shouldRedirectToGeneral || shouldRedirectToIndex) return null;
|
||||
|
||||
const requestBack = () => {
|
||||
if (section === undefined) return;
|
||||
|
||||
if (screenSize === ScreenSize.Mobile) {
|
||||
if (hasPreviousEntry) {
|
||||
navigate(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
navigate(getSettingsPath(), {
|
||||
replace: true,
|
||||
state: routeState?.backgroundLocation ? routeState : undefined,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let desktopBackState: SettingsRouteState | undefined;
|
||||
if (routeState?.backgroundLocation) {
|
||||
desktopBackState = routeState;
|
||||
} else if (routeState?.redirectedFromDesktopRoot) {
|
||||
desktopBackState = { redirectedFromDesktopRoot: true };
|
||||
}
|
||||
|
||||
navigate(getSettingsPath('general'), {
|
||||
replace: true,
|
||||
state: desktopBackState,
|
||||
});
|
||||
};
|
||||
|
||||
const requestClose = () => {
|
||||
if (section !== undefined && routeState?.redirectedFromDesktopRoot) {
|
||||
navigate(getHomePath(), { replace: true });
|
||||
return;
|
||||
}
|
||||
|
||||
if (section !== undefined && location.key === 'default') {
|
||||
navigate(getSettingsPath(), { replace: true, state: routeState });
|
||||
return;
|
||||
}
|
||||
|
||||
if (section === undefined && location.key === 'default') {
|
||||
navigate(getHomePath(), { replace: true });
|
||||
return;
|
||||
}
|
||||
|
||||
navigate(-1);
|
||||
const closeTarget = getSettingsCloseTarget(routeState);
|
||||
navigate(closeTarget.to, { replace: true, state: closeTarget.state });
|
||||
};
|
||||
|
||||
const handleSelectSection = (nextSection: SettingsSectionId) => {
|
||||
@@ -93,6 +111,7 @@ export function SettingsRoute() {
|
||||
return (
|
||||
<Settings
|
||||
activeSection={activeSection}
|
||||
onBack={requestBack}
|
||||
onSelectSection={handleSelectSection}
|
||||
requestClose={requestClose}
|
||||
/>
|
||||
|
||||
@@ -1,39 +1,46 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { Box, Icon, IconButton, Icons, Text } from 'folds';
|
||||
import { Page, PageHeader } from '$components/page';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
import { settingsHeader } from './styles.css';
|
||||
|
||||
type SettingsSectionPageProps = {
|
||||
title: ReactNode;
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
titleAs?: 'h1' | 'h2' | 'h3' | 'span' | 'div';
|
||||
backLabel?: string;
|
||||
actionLabel?: string;
|
||||
children?: ReactNode;
|
||||
};
|
||||
|
||||
export function SettingsSectionPage({
|
||||
title,
|
||||
requestBack,
|
||||
requestClose,
|
||||
titleAs,
|
||||
backLabel,
|
||||
actionLabel,
|
||||
children,
|
||||
}: SettingsSectionPageProps) {
|
||||
const screenSize = useScreenSizeContext();
|
||||
const isMobile = screenSize === ScreenSize.Mobile;
|
||||
const closeLabel = isMobile ? 'Back' : (actionLabel ?? 'Close');
|
||||
const closeLabel = actionLabel ?? 'Close';
|
||||
|
||||
return (
|
||||
<Page>
|
||||
<PageHeader outlined={false}>
|
||||
<PageHeader className={settingsHeader}>
|
||||
<Box grow="Yes" gap="200">
|
||||
<Box grow="Yes" alignItems="Center" gap="200">
|
||||
<Text size="H3" as={titleAs} truncate>
|
||||
{requestBack && (
|
||||
<IconButton aria-label={backLabel ?? 'Back'} onClick={requestBack} variant="Surface">
|
||||
<Icon src={Icons.ArrowLeft} />
|
||||
</IconButton>
|
||||
)}
|
||||
<Text size="H4" as={titleAs} truncate>
|
||||
{title}
|
||||
</Text>
|
||||
</Box>
|
||||
<Box shrink="No">
|
||||
<IconButton aria-label={closeLabel} onClick={requestClose} variant="Surface">
|
||||
<Icon src={isMobile ? Icons.ArrowLeft : Icons.Cross} />
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@@ -3,17 +3,24 @@ import { useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
import { Modal500 } from '$components/Modal500';
|
||||
import { isShallowSettingsRoute } from '$pages/client/ClientRouteOutlet';
|
||||
import { SETTINGS_PATH } from '$pages/paths';
|
||||
import { getSettingsCloseTarget, type SettingsRouteState } from './navigation';
|
||||
import { SettingsRoute } from './SettingsRoute';
|
||||
|
||||
export function SettingsShallowRouteRenderer() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const screenSize = useScreenSizeContext();
|
||||
const routeState = location.state as SettingsRouteState | null;
|
||||
|
||||
if (!isShallowSettingsRoute(location.pathname, location.state, screenSize)) return null;
|
||||
|
||||
const handleRequestClose = () => {
|
||||
const closeTarget = getSettingsCloseTarget(routeState);
|
||||
navigate(closeTarget.to, { replace: true, state: closeTarget.state });
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal500 requestClose={() => navigate(-1)}>
|
||||
<Modal500 requestClose={handleRequestClose}>
|
||||
<Routes>
|
||||
<Route path={SETTINGS_PATH} element={<SettingsRoute />} />
|
||||
</Routes>
|
||||
|
||||
@@ -51,7 +51,11 @@ export function HomeserverInfo() {
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<SettingTile title="Domain" description={mx.getSafeUserId().split(':')[1]} />
|
||||
<SettingTile
|
||||
title="Domain"
|
||||
focusId="domain"
|
||||
description={mx.getSafeUserId().split(':')[1]}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
@@ -61,6 +65,7 @@ export function HomeserverInfo() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Base URL"
|
||||
focusId="base-url"
|
||||
description={
|
||||
<a href={mx.baseUrl} target="_blank" rel="noopener noreferrer">
|
||||
{mx.baseUrl}
|
||||
@@ -77,6 +82,7 @@ export function HomeserverInfo() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Federation URL"
|
||||
focusId="federation-url"
|
||||
description={
|
||||
<a href={federationUrl} target="_blank" rel="noopener noreferrer">
|
||||
{federationUrl}
|
||||
@@ -104,7 +110,11 @@ export function HomeserverInfo() {
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<SettingTile title="Name" description={version.server?.name} />
|
||||
<SettingTile
|
||||
title="Name"
|
||||
focusId="homeserver-name"
|
||||
description={version.server?.name}
|
||||
/>
|
||||
</SequenceCard>
|
||||
)}
|
||||
{version.server?.version && (
|
||||
@@ -114,7 +124,11 @@ export function HomeserverInfo() {
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<SettingTile title="Version" description={version.server?.version} />
|
||||
<SettingTile
|
||||
title="Version"
|
||||
focusId="homeserver-version"
|
||||
description={version.server?.version}
|
||||
/>
|
||||
</SequenceCard>
|
||||
)}
|
||||
{version.server?.compiler && (
|
||||
@@ -124,7 +138,11 @@ export function HomeserverInfo() {
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<SettingTile title="Compiler" description={version.server?.compiler} />
|
||||
<SettingTile
|
||||
title="Compiler"
|
||||
focusId="homeserver-compiler"
|
||||
description={version.server?.compiler}
|
||||
/>
|
||||
</SequenceCard>
|
||||
)}
|
||||
</>
|
||||
@@ -143,16 +161,17 @@ export function HomeserverInfo() {
|
||||
}
|
||||
|
||||
type AboutProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function About({ requestClose }: Readonly<AboutProps>) {
|
||||
export function About({ requestBack, requestClose }: Readonly<AboutProps>) {
|
||||
const mx = useMatrixClient();
|
||||
const devLabel = IS_RELEASE_TAG ? '' : '-dev';
|
||||
const buildLabel = BUILD_HASH ? ` (${BUILD_HASH})` : '';
|
||||
const openBugReport = useOpenBugReportModal();
|
||||
|
||||
return (
|
||||
<SettingsSectionPage title="About" requestClose={requestClose}>
|
||||
<SettingsSectionPage title="About" requestBack={requestBack} requestClose={requestClose}>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
@@ -214,6 +233,7 @@ export function About({ requestClose }: Readonly<AboutProps>) {
|
||||
>
|
||||
<SettingTile
|
||||
title="Clear Cache & Reload"
|
||||
focusId="clear-cache-and-reload"
|
||||
description="Clear all your locally stored data and reload from server."
|
||||
after={
|
||||
<Button
|
||||
@@ -237,6 +257,7 @@ export function About({ requestClose }: Readonly<AboutProps>) {
|
||||
>
|
||||
<SettingTile
|
||||
title="Report an Issue"
|
||||
focusId="report-an-issue"
|
||||
description="Report a bug or request a feature on GitHub."
|
||||
after={
|
||||
<Button
|
||||
|
||||
@@ -7,11 +7,12 @@ import { ContactInformation } from './ContactInfo';
|
||||
import { IgnoredUserList } from './IgnoredUserList';
|
||||
|
||||
type AccountProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function Account({ requestClose }: AccountProps) {
|
||||
export function Account({ requestBack, requestClose }: AccountProps) {
|
||||
return (
|
||||
<SettingsSectionPage title="Account" requestClose={requestClose}>
|
||||
<SettingsSectionPage title="Account" requestBack={requestBack} requestClose={requestClose}>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
|
||||
@@ -40,6 +40,7 @@ export function AnimalCosmetics({ profile, userId }: Readonly<AnimalCosmeticsPro
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Render Animals"
|
||||
focusId="render-animals"
|
||||
description="Render animals as animals as opposed to normal humans."
|
||||
after={<Switch variant="Primary" value={renderAnimals} onChange={setRenderAnimals} />}
|
||||
/>
|
||||
@@ -47,6 +48,7 @@ export function AnimalCosmetics({ profile, userId }: Readonly<AnimalCosmeticsPro
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Is Cat"
|
||||
focusId="is-cat"
|
||||
description="Marks you as a cat."
|
||||
after={
|
||||
<Switch
|
||||
@@ -60,6 +62,7 @@ export function AnimalCosmetics({ profile, userId }: Readonly<AnimalCosmeticsPro
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Has Cats"
|
||||
focusId="has-cats"
|
||||
description="Marks that you have cats."
|
||||
after={
|
||||
<Switch
|
||||
|
||||
@@ -167,7 +167,7 @@ export function BioEditor({ value, isSaving, imagePackRooms, onSave }: BioEditor
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<SettingTile title="About You" description="Customize your bio." />
|
||||
<SettingTile title="About You" focusId="about-you" description="Customize your bio." />
|
||||
<Box className={css.BioEditorContainer} direction="Column" style={{ position: 'relative' }}>
|
||||
{autocompleteQuery?.prefix === AutocompletePrefix.Emoticon && (
|
||||
<EmoticonAutocomplete
|
||||
|
||||
@@ -29,7 +29,11 @@ export function ContactInformation() {
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<SettingTile title="Email Address" description="Email address attached to your account.">
|
||||
<SettingTile
|
||||
title="Email Address"
|
||||
focusId="email-address"
|
||||
description="Email address attached to your account."
|
||||
>
|
||||
<Box>
|
||||
{emailIds?.map((email) => (
|
||||
<Chip key={email.address} as="span" variant="Secondary" radii="Pill">
|
||||
|
||||
@@ -144,6 +144,7 @@ export function IgnoredUserList() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Select User"
|
||||
focusId="blocked-users"
|
||||
description="Prevent receiving messages or invites from user by adding their userId."
|
||||
>
|
||||
<Box direction="Column" gap="300">
|
||||
|
||||
@@ -20,6 +20,7 @@ export function MatrixId() {
|
||||
>
|
||||
<SettingTile
|
||||
title={userId}
|
||||
focusId="matrix-id"
|
||||
after={
|
||||
<Chip variant="Secondary" radii="Pill" onClick={() => copyToClipboard(userId)}>
|
||||
<Text size="T200">Copy</Text>
|
||||
|
||||
@@ -57,7 +57,7 @@ export function NameColorEditor({
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<SettingTile title={title} description={description} />
|
||||
<SettingTile title={title} focusId="name-color" description={description} />
|
||||
<Box
|
||||
alignItems="Center"
|
||||
justifyContent="SpaceBetween"
|
||||
|
||||
@@ -38,6 +38,7 @@ import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { useFilePicker } from '$hooks/useFilePicker';
|
||||
import { useObjectURL } from '$hooks/useObjectURL';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { toSettingsFocusIdPart } from '$features/settings/settingsLink';
|
||||
import { ImageEditor } from '$components/image-editor';
|
||||
import { ModalWide } from '$styles/Modal.css';
|
||||
import { createUploadAtom, UploadSuccess } from '$state/upload';
|
||||
@@ -104,6 +105,7 @@ function ProfileAvatar({ profile, userId }: Readonly<ProfileProps>) {
|
||||
return (
|
||||
<SettingTile
|
||||
title="Avatar"
|
||||
focusId="avatar"
|
||||
after={
|
||||
<Avatar size="500" radii="300">
|
||||
<UserAvatar
|
||||
@@ -279,7 +281,7 @@ function ProfileBanner({ profile, userId }: Readonly<ProfileProps>) {
|
||||
const previewUrl = isRemoving ? undefined : imageFileURL || stagedUrl || bannerUrl;
|
||||
|
||||
return (
|
||||
<SettingTile title="Banner">
|
||||
<SettingTile title="Banner" focusId="banner">
|
||||
<Box direction="Column" gap="300" grow="Yes">
|
||||
<Box
|
||||
style={{
|
||||
@@ -425,7 +427,7 @@ function ProfileDisplayName({ profile, userId }: Readonly<ProfileProps>) {
|
||||
|
||||
const hasChanges = displayName !== defaultDisplayName;
|
||||
return (
|
||||
<SettingTile title="Display Name">
|
||||
<SettingTile title="Display Name" focusId="display-name">
|
||||
<Box direction="Column" grow="Yes" gap="100">
|
||||
<Box
|
||||
as="form"
|
||||
@@ -621,6 +623,7 @@ function ProfileExtended({ profile, userId }: Readonly<ProfileProps>) {
|
||||
>
|
||||
<SettingTile
|
||||
key={key}
|
||||
focusId={`profile-field-${toSettingsFocusIdPart(key)}`}
|
||||
title={key.split('.').pop() || key}
|
||||
description={key}
|
||||
after={
|
||||
|
||||
@@ -32,6 +32,7 @@ export function PronounEditor({ title, current, onSave, disabled }: PronounEdito
|
||||
return (
|
||||
<SettingTile
|
||||
title={title}
|
||||
focusId="pronouns"
|
||||
// let people specify multiple sets of pronouns for different languages
|
||||
// the input is a comma separated list of pronoun sets, each set can have an optional language tag (e.g. "en:they/them, de:sie/ihr")
|
||||
description="Separate sets with commas (e.g. 'en:they/them, en:it/its, de:sie/ihr')."
|
||||
|
||||
@@ -39,7 +39,7 @@ export function StatusEditor({ current = '', onSave }: StatusEditorProps) {
|
||||
const hasChanges = value !== current;
|
||||
|
||||
return (
|
||||
<SettingTile title="Status">
|
||||
<SettingTile title="Status" focusId="status">
|
||||
<Box direction="Column" grow="Yes" gap="100">
|
||||
<Box as="form" onSubmit={handleSubmit} gap="200" aria-disabled={saving} grow="Yes">
|
||||
<Box grow="Yes" direction="Column">
|
||||
|
||||
@@ -47,6 +47,7 @@ export function TimezoneEditor({ current, onSave }: TimezoneEditorProps) {
|
||||
return (
|
||||
<SettingTile
|
||||
title="Timezone"
|
||||
focusId="timezone"
|
||||
description="Set manually or sync with your system."
|
||||
after={
|
||||
<Box gap="200" alignItems="Center">
|
||||
|
||||
@@ -109,6 +109,7 @@ function JumboEmoji() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Jumbo Emoji Size"
|
||||
focusId="jumbo-emoji-size"
|
||||
description="Adjust the size of emojis sent without text."
|
||||
after={<SelectJumboEmojiSize />}
|
||||
/>
|
||||
@@ -132,6 +133,7 @@ function Privacy() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Blur Media"
|
||||
focusId="blur-media"
|
||||
description="Blurs images and videos in the timeline."
|
||||
after={<Switch variant="Primary" value={privacyBlur} onChange={setPrivacyBlur} />}
|
||||
/>
|
||||
@@ -140,6 +142,7 @@ function Privacy() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Blur Avatars"
|
||||
focusId="blur-avatars"
|
||||
description="Blurs user profile pictures and room icons."
|
||||
after={
|
||||
<Switch variant="Primary" value={privacyBlurAvatars} onChange={setPrivacyBlurAvatars} />
|
||||
@@ -150,6 +153,7 @@ function Privacy() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Blur Emotes"
|
||||
focusId="blur-emotes"
|
||||
description="Blurs emoticons within messages."
|
||||
after={
|
||||
<Switch variant="Primary" value={privacyBlurEmotes} onChange={setPrivacyBlurEmotes} />
|
||||
@@ -181,6 +185,7 @@ function IdentityCosmetics() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Colorful Names"
|
||||
focusId="colorful-names"
|
||||
description="Assign unique colors to users based on their ID. Does not override room/space custom colors. Will override default role colors."
|
||||
after={
|
||||
<Switch
|
||||
@@ -194,6 +199,7 @@ function IdentityCosmetics() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Pronoun Pills"
|
||||
focusId="show-pronoun-pills"
|
||||
description="Display user pronouns in the message timeline."
|
||||
after={<Switch variant="Primary" value={showPronouns} onChange={setShowPronouns} />}
|
||||
/>
|
||||
@@ -201,6 +207,7 @@ function IdentityCosmetics() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Pronoun Pills for All"
|
||||
focusId="pronoun-pills-for-all"
|
||||
description="Attempts to convert pronouns in names into pills (e.g. [they/them] or (it/its) turns into a pill)."
|
||||
after={<Switch variant="Primary" value={parsePronouns} onChange={setParsePronouns} />}
|
||||
/>
|
||||
@@ -208,6 +215,7 @@ function IdentityCosmetics() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Render Global Username Colors"
|
||||
focusId="render-global-username-colors"
|
||||
description="Display the username colors anyone can set in their account settings."
|
||||
after={
|
||||
<Switch variant="Primary" value={renderGlobalColors} onChange={setRenderGlobalColors} />
|
||||
@@ -217,6 +225,7 @@ function IdentityCosmetics() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Render Space/Room Username Colors"
|
||||
focusId="render-space-room-username-colors"
|
||||
description="Display the username colors that can be set with /color."
|
||||
after={
|
||||
<Switch variant="Primary" value={renderRoomColors} onChange={setRenderRoomColors} />
|
||||
@@ -226,6 +235,7 @@ function IdentityCosmetics() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Render Space/Room Fonts"
|
||||
focusId="render-space-room-fonts"
|
||||
description="Display the username fonts that can be set with /font."
|
||||
after={<Switch variant="Primary" value={renderRoomFonts} onChange={setRenderRoomFonts} />}
|
||||
/>
|
||||
@@ -233,6 +243,7 @@ function IdentityCosmetics() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Consistent Icon Style"
|
||||
focusId="consistent-icon-style"
|
||||
description="Harmonize icon appearance with background fill"
|
||||
after={<Switch variant="Primary" value={uniformIcons} onChange={setUniformIcons} />}
|
||||
/>
|
||||
@@ -242,12 +253,13 @@ function IdentityCosmetics() {
|
||||
}
|
||||
|
||||
type CosmeticsProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
|
||||
export function Cosmetics({ requestClose }: CosmeticsProps) {
|
||||
export function Cosmetics({ requestBack, requestClose }: CosmeticsProps) {
|
||||
return (
|
||||
<SettingsSectionPage title="Appearance" requestClose={requestClose}>
|
||||
<SettingsSectionPage title="Appearance" requestBack={requestBack} requestClose={requestClose}>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
|
||||
@@ -78,6 +78,7 @@ export function LanguageSpecificPronouns() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Show pronouns only in selected language"
|
||||
focusId="show-pronouns-only-in-selected-language"
|
||||
description="If enabled, pronouns are only shown when they match your selected language. This helps if your contacts set pronouns in different languages. It doesn't affect how your pronouns are shared with others."
|
||||
after={
|
||||
<Switch
|
||||
@@ -90,6 +91,7 @@ export function LanguageSpecificPronouns() {
|
||||
{useLanguageSpecificPronouns && (
|
||||
<SettingTile
|
||||
title="Selected language for pronouns"
|
||||
focusId="selected-language-for-pronouns"
|
||||
description="The language to show pronouns for when the above setting is enabled."
|
||||
after={
|
||||
<Input
|
||||
|
||||
@@ -158,6 +158,7 @@ function SystemThemePreferences() {
|
||||
<Box wrap="Wrap" gap="400">
|
||||
<SettingTile
|
||||
title="Light Theme:"
|
||||
focusId="light-theme"
|
||||
after={
|
||||
<Chip
|
||||
variant={themeKind === ThemeKind.Light ? 'Primary' : 'Secondary'}
|
||||
@@ -199,6 +200,7 @@ function SystemThemePreferences() {
|
||||
/>
|
||||
<SettingTile
|
||||
title="Dark Theme:"
|
||||
focusId="dark-theme"
|
||||
after={
|
||||
<Chip
|
||||
variant={themeKind === ThemeKind.Dark ? 'Primary' : 'Secondary'}
|
||||
@@ -263,6 +265,7 @@ function ThemeSettings() {
|
||||
>
|
||||
<SettingTile
|
||||
title="System Theme"
|
||||
focusId="system-theme"
|
||||
description="Sync with your device's light/dark mode."
|
||||
after={<Switch variant="Primary" value={systemTheme} onChange={setSystemTheme} />}
|
||||
/>
|
||||
@@ -272,6 +275,7 @@ function ThemeSettings() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Manual Theme"
|
||||
focusId="manual-theme"
|
||||
description="Active when System Theme is disabled."
|
||||
after={<SelectTheme disabled={systemTheme} />}
|
||||
/>
|
||||
@@ -280,6 +284,7 @@ function ThemeSettings() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Saturation"
|
||||
focusId="saturation"
|
||||
description={`${saturation}%`}
|
||||
after={
|
||||
<input
|
||||
@@ -305,6 +310,7 @@ function ThemeSettings() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Underline Links"
|
||||
focusId="underline-links"
|
||||
description="Always show underlines on links in chat, bios and room descriptions."
|
||||
after={<Switch variant="Primary" value={underlineLinks} onChange={setUnderlineLinks} />}
|
||||
/>
|
||||
@@ -312,6 +318,7 @@ function ThemeSettings() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Reduced Motion"
|
||||
focusId="reduced-motion"
|
||||
description="Stops animations and sliding UI elements."
|
||||
after={<Switch variant="Primary" value={reducedMotion} onChange={setReducedMotion} />}
|
||||
/>
|
||||
@@ -319,6 +326,7 @@ function ThemeSettings() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Autoplay GIFs"
|
||||
focusId="autoplay-gifs"
|
||||
description="Automatically play animated image uploads and links."
|
||||
after={<Switch variant="Primary" value={autoplayGifs} onChange={setAutoplayGifs} />}
|
||||
/>
|
||||
@@ -326,6 +334,7 @@ function ThemeSettings() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Autoplay Stickers"
|
||||
focusId="autoplay-stickers"
|
||||
description="Automatically play animated stickers."
|
||||
after={
|
||||
<Switch variant="Primary" value={autoplayStickers} onChange={setAutoplayStickers} />
|
||||
@@ -335,6 +344,7 @@ function ThemeSettings() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Autoplay Emojis"
|
||||
focusId="autoplay-emojis"
|
||||
description="Automatically play animated custom emojis."
|
||||
after={<Switch variant="Primary" value={autoplayEmojis} onChange={setAutoplayEmojis} />}
|
||||
/>
|
||||
@@ -446,6 +456,7 @@ export function Appearance() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Twitter Emoji"
|
||||
focusId="twitter-emoji"
|
||||
description="Use Twitter-style emojis instead of system native ones."
|
||||
after={<Switch variant="Primary" value={twitterEmoji} onChange={setTwitterEmoji} />}
|
||||
/>
|
||||
@@ -454,18 +465,20 @@ export function Appearance() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Easter Eggs"
|
||||
focusId="show-easter-eggs"
|
||||
description="Lets the interface keep a little mischief turned on."
|
||||
after={<Switch variant="Primary" value={showEasterEggs} onChange={setShowEasterEggs} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="Page Zoom" after={<PageZoomInput />} />
|
||||
<SettingTile title="Page Zoom" focusId="page-zoom" after={<PageZoomInput />} />
|
||||
</SequenceCard>
|
||||
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Subspace Hierarchy Limit"
|
||||
focusId="subspace-hierarchy-limit"
|
||||
description="The maximum nesting depth for Subspaces in the sidebar. Once this limit is reached, deeper Subspaces appear as links instead of nested folders."
|
||||
after={<SubnestedSpaceLinkDepthInput />}
|
||||
/>
|
||||
|
||||
@@ -38,6 +38,7 @@ export function AccountData({ expand, onExpandToggle, onSelect }: AccountDataPro
|
||||
>
|
||||
<SettingTile
|
||||
title="Global"
|
||||
focusId="global-account-data"
|
||||
description="Data stored in your global account data."
|
||||
after={
|
||||
<Button
|
||||
|
||||
@@ -16,9 +16,10 @@ import { DebugLogViewer } from './DebugLogViewer';
|
||||
import { SentrySettings } from './SentrySettings';
|
||||
|
||||
type DeveloperToolsProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
||||
export function DeveloperTools({ requestBack, requestClose }: DeveloperToolsProps) {
|
||||
const mx = useMatrixClient();
|
||||
const [developerTools, setDeveloperTools] = useSetting(settingsAtom, 'developerTools');
|
||||
const [expand, setExpend] = useState(false);
|
||||
@@ -49,7 +50,11 @@ export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingsSectionPage title="Developer Tools" requestClose={requestClose}>
|
||||
<SettingsSectionPage
|
||||
title="Developer Tools"
|
||||
requestBack={requestBack}
|
||||
requestClose={requestClose}
|
||||
>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
@@ -64,6 +69,7 @@ export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
||||
>
|
||||
<SettingTile
|
||||
title="Enable Developer Tools"
|
||||
focusId="enable-developer-tools"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -82,6 +88,7 @@ export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
||||
>
|
||||
<SettingTile
|
||||
title="Access Token"
|
||||
focusId="access-token"
|
||||
description="Copy access token to clipboard."
|
||||
after={
|
||||
<Button
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Box, Text, Switch, Button } from 'folds';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { SequenceCardStyle } from '$features/settings/styles.css';
|
||||
import { toSettingsFocusIdPart } from '$features/settings/settingsLink';
|
||||
import { getDebugLogger, LogCategory } from '$utils/debugLogger';
|
||||
|
||||
const ALL_CATEGORIES: LogCategory[] = [
|
||||
@@ -87,14 +88,17 @@ export function SentrySettings() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Traces & Profiles"
|
||||
focusId="traces-profiles"
|
||||
description={`Current environment: ${environment}. Sample rate: ${traceSampleRate}`}
|
||||
/>
|
||||
<SettingTile
|
||||
title="Session Replay"
|
||||
focusId="session-replay"
|
||||
description={`Session sample rate: ${replaySampleRate} · On-error rate: 100%`}
|
||||
/>
|
||||
<SettingTile
|
||||
title="Session Error Budget"
|
||||
focusId="session-error-budget"
|
||||
description="At most 50 error events are forwarded to Sentry per page load to prevent quota exhaustion."
|
||||
/>
|
||||
</SequenceCard>
|
||||
@@ -113,6 +117,7 @@ export function SentrySettings() {
|
||||
{ALL_CATEGORIES.map((cat) => (
|
||||
<SettingTile
|
||||
key={cat}
|
||||
focusId={`sentry-category-${toSettingsFocusIdPart(cat)}`}
|
||||
title={cat.charAt(0).toUpperCase() + cat.slice(1)}
|
||||
after={
|
||||
<Switch
|
||||
@@ -134,10 +139,12 @@ export function SentrySettings() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Session Activity"
|
||||
focusId="session-activity"
|
||||
description={`Errors captured: ${sentryStats.errors} · Warnings captured: ${sentryStats.warnings} (updates every 5 s)`}
|
||||
/>
|
||||
<SettingTile
|
||||
title="Export Debug Logs"
|
||||
focusId="export-debug-logs"
|
||||
description="Download the current in-memory debug log buffer as a JSON file for offline analysis."
|
||||
after={
|
||||
<Button variant="Secondary" size="300" onClick={handleExportLogs}>
|
||||
|
||||
@@ -28,6 +28,7 @@ import { stopPropagation } from '$utils/keyboard';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { SequenceCardStyle } from '$features/settings/styles.css';
|
||||
import { toSettingsFocusIdPart } from '$features/settings/settingsLink';
|
||||
|
||||
export function DeviceTilePlaceholder() {
|
||||
return (
|
||||
@@ -285,6 +286,7 @@ export function DeviceTile({
|
||||
return (
|
||||
<>
|
||||
<SettingTile
|
||||
focusId={`device-${toSettingsFocusIdPart(device.device_id)}`}
|
||||
before={
|
||||
<IconButton
|
||||
variant={deleted ? 'Critical' : 'Secondary'}
|
||||
|
||||
@@ -34,9 +34,10 @@ function DevicesPlaceholder() {
|
||||
}
|
||||
|
||||
type DevicesProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function Devices({ requestClose }: DevicesProps) {
|
||||
export function Devices({ requestBack, requestClose }: DevicesProps) {
|
||||
const mx = useMatrixClient();
|
||||
const crypto = mx.getCrypto();
|
||||
const crossSigningActive = useCrossSigningActive();
|
||||
@@ -62,7 +63,7 @@ export function Devices({ requestClose }: DevicesProps) {
|
||||
);
|
||||
|
||||
return (
|
||||
<SettingsSectionPage title="Devices" requestClose={requestClose}>
|
||||
<SettingsSectionPage title="Devices" requestBack={requestBack} requestClose={requestClose}>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
@@ -77,6 +78,7 @@ export function Devices({ requestClose }: DevicesProps) {
|
||||
>
|
||||
<SettingTile
|
||||
title="Device Verification"
|
||||
focusId="device-verification"
|
||||
description="To verify device identity and grant access to encrypted messages."
|
||||
after={
|
||||
<>
|
||||
|
||||
@@ -73,7 +73,7 @@ function ExportKeys() {
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingTile>
|
||||
<SettingTile focusId="export-messages-data">
|
||||
<Box as="form" onSubmit={handleSubmit} direction="Column" gap="100">
|
||||
<Box gap="200" alignItems="End">
|
||||
<ConfirmPasswordMatch initialValue>
|
||||
@@ -142,6 +142,7 @@ function ExportKeysTile() {
|
||||
<>
|
||||
<SettingTile
|
||||
title="Export Messages Data"
|
||||
focusId="export-messages-data"
|
||||
description="Save password protected copy of encryption data on your device to decrypt messages later."
|
||||
after={
|
||||
<Box>
|
||||
@@ -219,7 +220,7 @@ function ImportKeys({ file, onDone }: ImportKeysProps) {
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingTile>
|
||||
<SettingTile focusId="import-messages-data">
|
||||
<Box as="form" onSubmit={handleSubmit} direction="Column" gap="100">
|
||||
<Box gap="200" alignItems="End">
|
||||
<Box grow="Yes" direction="Column" gap="100">
|
||||
@@ -271,6 +272,7 @@ function ImportKeysTile() {
|
||||
<>
|
||||
<SettingTile
|
||||
title="Import Messages Data"
|
||||
focusId="import-messages-data"
|
||||
description="Load password protected copy of encryption data from device to decrypt your messages."
|
||||
after={
|
||||
<Box>
|
||||
|
||||
@@ -114,6 +114,7 @@ export function OtherDevices({ devices, refreshDeviceList, showVerification }: O
|
||||
>
|
||||
<SettingTile
|
||||
title="Device Dashboard"
|
||||
focusId="device-dashboard"
|
||||
description="Manage your devices on OIDC dashboard."
|
||||
after={
|
||||
<Button
|
||||
|
||||
@@ -8,9 +8,10 @@ import { GlobalPacks } from './GlobalPacks';
|
||||
import { UserPack } from './UserPack';
|
||||
|
||||
type EmojisStickersProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function EmojisStickers({ requestClose }: EmojisStickersProps) {
|
||||
export function EmojisStickers({ requestBack, requestClose }: EmojisStickersProps) {
|
||||
const [imagePack, setImagePack] = useState<ImagePack>();
|
||||
|
||||
const handleImagePackViewClose = () => {
|
||||
@@ -22,7 +23,11 @@ export function EmojisStickers({ requestClose }: EmojisStickersProps) {
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingsSectionPage title="Emojis & Stickers" requestClose={requestClose}>
|
||||
<SettingsSectionPage
|
||||
title="Emojis & Stickers"
|
||||
requestBack={requestBack}
|
||||
requestClose={requestClose}
|
||||
>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
|
||||
@@ -30,6 +30,7 @@ import { SettingTile } from '$components/setting-tile';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { toSettingsFocusIdPart } from '$features/settings/settingsLink';
|
||||
import {
|
||||
EmoteRoomsContent,
|
||||
ImagePack,
|
||||
@@ -185,6 +186,7 @@ function GlobalPackSelector({
|
||||
>
|
||||
<SettingTile
|
||||
title={pack.meta.name ?? 'Unknown'}
|
||||
focusId={`room-pack-${toSettingsFocusIdPart(pack.id)}`}
|
||||
description={<span className={LineClamp2}>{pack.meta.attribution}</span>}
|
||||
before={
|
||||
<Box alignItems="Center" gap="300">
|
||||
@@ -358,6 +360,7 @@ export function GlobalPacks({ onViewPack }: GlobalPacksProps) {
|
||||
gap="400"
|
||||
>
|
||||
<SettingTile
|
||||
focusId={`selected-pack-${toSettingsFocusIdPart(pack.id)}`}
|
||||
title={
|
||||
<span style={{ textDecoration: removed ? 'line-through' : undefined }}>
|
||||
{pack.meta.name ?? 'Unknown'}
|
||||
@@ -429,6 +432,7 @@ export function GlobalPacks({ onViewPack }: GlobalPacksProps) {
|
||||
>
|
||||
<SettingTile
|
||||
title="Select Pack"
|
||||
focusId="select-pack"
|
||||
description="Pick emojis and stickers pack from rooms to use in all rooms."
|
||||
after={
|
||||
<>
|
||||
|
||||
@@ -39,6 +39,7 @@ export function UserPack({ onViewPack }: UserPackProps) {
|
||||
>
|
||||
<SettingTile
|
||||
title={userPack?.meta.name ?? 'Unknown'}
|
||||
focusId="default-pack"
|
||||
description={userPack?.meta.attribution}
|
||||
before={
|
||||
<Avatar size="300" radii="300">
|
||||
|
||||
@@ -22,6 +22,7 @@ export function BandwidthSavingEmojis() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Enable bandwidth saving for stickers and emojis"
|
||||
focusId="bandwidth-saving-emojis"
|
||||
description="If enabled, sticker and emoji images will be optimized to save bandwidth. This helps reduce data usage when viewing these images. But will increase server computation load."
|
||||
after={
|
||||
<Switch variant="Primary" value={useBandwidthSaving} onChange={setUseBandwidthSaving} />
|
||||
|
||||
@@ -23,6 +23,7 @@ function PersonaToggle() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Personas Tab"
|
||||
focusId="show-personas-tab"
|
||||
description="Enables the personas tab in the settings menu for per-message profiles"
|
||||
after={
|
||||
<Switch variant="Primary" value={showPersonaSetting} onChange={setShowPersonaSetting} />
|
||||
@@ -34,11 +35,12 @@ function PersonaToggle() {
|
||||
}
|
||||
|
||||
type ExperimentalProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function Experimental({ requestClose }: Readonly<ExperimentalProps>) {
|
||||
export function Experimental({ requestBack, requestClose }: Readonly<ExperimentalProps>) {
|
||||
return (
|
||||
<SettingsSectionPage title="Experimental" requestClose={requestClose}>
|
||||
<SettingsSectionPage title="Experimental" requestBack={requestBack} requestClose={requestClose}>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
|
||||
@@ -22,6 +22,7 @@ export function MSC4268HistoryShare() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Enable the /sharehistory command"
|
||||
focusId="sharehistory-command"
|
||||
description="If enabled, this command will allow users to share encrypted history with other newly joined users, as per MSC4268."
|
||||
after={
|
||||
<Switch
|
||||
|
||||
@@ -54,6 +54,7 @@ import { isKeyHotkey } from 'is-hotkey';
|
||||
import { settingsSyncLastSyncedAtom, settingsSyncStatusAtom } from '$hooks/useSettingsSync';
|
||||
import { exportSettingsAsJson, importSettingsFromJson } from '$utils/settingsSync';
|
||||
import { SettingsSectionPage } from '../SettingsSectionPage';
|
||||
import { SettingsLinkBaseUrlSetting } from './SettingsLinkBaseUrlSetting';
|
||||
|
||||
type DateHintProps = {
|
||||
hasChanges: boolean;
|
||||
@@ -255,7 +256,7 @@ function CustomDateFormat({ value, onChange }: Readonly<CustomDateFormatProps>)
|
||||
|
||||
const hasChanges = dateFormatCustom !== value;
|
||||
return (
|
||||
<SettingTile>
|
||||
<SettingTile focusId="custom-date-format">
|
||||
<Box as="form" onSubmit={handleSubmit} gap="200">
|
||||
<Box grow="Yes" direction="Column">
|
||||
<Input
|
||||
@@ -378,6 +379,7 @@ function SelectDateFormat() {
|
||||
<>
|
||||
<SettingTile
|
||||
title="Date Format"
|
||||
focusId="date-format"
|
||||
description={customDateFormat ? dayjs().format(dateFormatString) : ''}
|
||||
after={<PresetDateFormat value={selectedDateFormat} onChange={handlePresetChange} />}
|
||||
/>
|
||||
@@ -407,6 +409,7 @@ function DateAndTime() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="24-Hour Time Format"
|
||||
focusId="twenty-four-hour-time-format"
|
||||
after={<Switch variant="Primary" value={hour24Clock} onChange={setHour24Clock} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
@@ -437,6 +440,7 @@ function Editor({ isMobile }: Readonly<{ isMobile: boolean }>) {
|
||||
>
|
||||
<SettingTile
|
||||
title="ENTER for Newline"
|
||||
focusId="enter-for-newline"
|
||||
description={`Use ${isMacOS() ? KeySymbol.Command : 'Ctrl'} + ENTER to send message. ${isMobile ? '(Disabled on Mobile)' : ''}`}
|
||||
after={
|
||||
<Switch
|
||||
@@ -451,12 +455,14 @@ function Editor({ isMobile }: Readonly<{ isMobile: boolean }>) {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Markdown Formatting"
|
||||
focusId="markdown-formatting"
|
||||
after={<Switch variant="Primary" value={isMarkdown} onChange={setIsMarkdown} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Hide Typing Indicators"
|
||||
focusId="hide-typing-indicators"
|
||||
description="Turn off typing status."
|
||||
after={<Switch variant="Primary" value={hideActivity} onChange={setHideActivity} />}
|
||||
/>
|
||||
@@ -464,6 +470,7 @@ function Editor({ isMobile }: Readonly<{ isMobile: boolean }>) {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Hide Read Receipts"
|
||||
focusId="hide-read-receipts"
|
||||
description="Turn off read receipts."
|
||||
after={<Switch variant="Primary" value={hideReads} onChange={setHideReads} />}
|
||||
/>
|
||||
@@ -471,6 +478,7 @@ function Editor({ isMobile }: Readonly<{ isMobile: boolean }>) {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Presence Status"
|
||||
focusId="presence-status"
|
||||
description="Show and receive online status from other users."
|
||||
after={<Switch variant="Primary" value={sendPresence} onChange={setSendPresence} />}
|
||||
/>
|
||||
@@ -478,6 +486,7 @@ function Editor({ isMobile }: Readonly<{ isMobile: boolean }>) {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Send notifications for replies"
|
||||
focusId="reply-notifications"
|
||||
description="Disable to use silent replies by default. You can still toggle reply notifications for each reply."
|
||||
after={
|
||||
<Switch variant="Primary" value={mentionInReplies} onChange={setMentionInReplies} />
|
||||
@@ -771,6 +780,7 @@ function Gestures({ isMobile }: Readonly<{ isMobile: boolean }>) {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Enable Swiping"
|
||||
focusId="enable-swiping"
|
||||
description="Swipe left for rooms, swipe right for actions."
|
||||
after={
|
||||
<Switch
|
||||
@@ -785,6 +795,7 @@ function Gestures({ isMobile }: Readonly<{ isMobile: boolean }>) {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Right Swipe Action"
|
||||
focusId="right-swipe-action"
|
||||
description="What happens when you swipe right on a message."
|
||||
after={<SelectRightSwipeAction disabled={!isMobile || !mobileGestures} />}
|
||||
/>
|
||||
@@ -848,6 +859,7 @@ function Calls() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Call Button for Large Rooms"
|
||||
focusId="large-room-call-button"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -898,17 +910,30 @@ function Messages() {
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Messages</Text>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="Message Layout" after={<SelectMessageLayout />} />
|
||||
<SettingTile
|
||||
title="Message Layout"
|
||||
focusId="message-layout"
|
||||
after={<SelectMessageLayout />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="Message Spacing" after={<SelectMessageSpacing />} />
|
||||
<SettingTile
|
||||
title="Message Spacing"
|
||||
focusId="message-spacing"
|
||||
after={<SelectMessageSpacing />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="File description placement" after={<SelectCaptionPosition />} />
|
||||
<SettingTile
|
||||
title="File description placement"
|
||||
focusId="file-description-placement"
|
||||
after={<SelectCaptionPosition />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Emoji Selector Character Threshold"
|
||||
focusId="emoji-selector-threshold"
|
||||
after={<EmojiSelectorThresholdInput />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
@@ -916,6 +941,7 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Right Aligned Bubbles"
|
||||
focusId="right-aligned-bubbles"
|
||||
description="While using bubble layout, have your bubbles right aligned."
|
||||
after={<Switch variant="Primary" value={rightBubbles} onChange={setRightBubbles} />}
|
||||
/>
|
||||
@@ -924,6 +950,7 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Hide Membership Change"
|
||||
focusId="hide-membership-change"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -936,6 +963,7 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Hide Profile Change"
|
||||
focusId="hide-profile-change"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -948,6 +976,7 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Disable Media Auto Load"
|
||||
focusId="disable-media-auto-load"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -960,18 +989,21 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Url Preview"
|
||||
focusId="url-preview"
|
||||
after={<Switch variant="Primary" value={urlPreview} onChange={setUrlPreview} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Url Preview in Encrypted Room"
|
||||
focusId="encrypted-room-url-preview"
|
||||
after={<Switch variant="Primary" value={encUrlPreview} onChange={setEncUrlPreview} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Client Side Embeds"
|
||||
focusId="client-side-embeds"
|
||||
description="Attempt to preview unsupported urls (e.g. YouTube) on the client, without involving the homeserver. This will expose your IP Address to third party services."
|
||||
after={
|
||||
<Switch
|
||||
@@ -991,6 +1023,7 @@ function Messages() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Client Embeds in Encrypted Rooms"
|
||||
focusId="encrypted-room-embeds"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -1013,6 +1046,7 @@ function Messages() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Embed YouTube Links"
|
||||
focusId="embed-youtube-links"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -1027,9 +1061,13 @@ function Messages() {
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingsLinkBaseUrlSetting />
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Hide Member Events in Read-Only Rooms"
|
||||
focusId="hide-member-events-read-only-rooms"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -1042,6 +1080,7 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Hidden Events"
|
||||
focusId="show-hidden-events"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -1059,6 +1098,7 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Tombstones for Redacted Messages"
|
||||
focusId="show-redacted-message-tombstones"
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
@@ -1109,6 +1149,7 @@ export function Sync() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Use Sliding Sync"
|
||||
focusId="use-sliding-sync"
|
||||
description={
|
||||
serverSlidingEnabled ? (
|
||||
<>
|
||||
@@ -1160,6 +1201,7 @@ export function Sync() {
|
||||
}
|
||||
|
||||
type GeneralProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
|
||||
@@ -1201,11 +1243,16 @@ function SettingsSyncSection() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Sync across devices"
|
||||
focusId="sync-across-devices"
|
||||
description="Store your settings in your Matrix account so they follow you to any Sable instance. Notification and zoom preferences are kept per-device."
|
||||
after={<Switch variant="Primary" value={syncEnabled} onChange={setSyncEnabled} />}
|
||||
/>
|
||||
{syncEnabled && (
|
||||
<SettingTile title="Sync status" description={syncStatusLabel[syncStatus]} />
|
||||
<SettingTile
|
||||
focusId="sync-status"
|
||||
title="Sync status"
|
||||
description={syncStatusLabel[syncStatus]}
|
||||
/>
|
||||
)}
|
||||
</SequenceCard>
|
||||
<Box gap="200" wrap="Wrap" style={{ paddingTop: '4px' }}>
|
||||
@@ -1294,6 +1341,7 @@ function DiagnosticsAndPrivacy() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Error Reporting"
|
||||
focusId="error-reporting"
|
||||
description={
|
||||
isSentryConfigured
|
||||
? 'Send anonymous crash reports to help improve Sable. No messages, room names, or personal data are included.'
|
||||
@@ -1311,6 +1359,7 @@ function DiagnosticsAndPrivacy() {
|
||||
{sentryEnabled && isSentryConfigured && (
|
||||
<SettingTile
|
||||
title="Session Replay"
|
||||
focusId="session-replay"
|
||||
description="Allow recording of UI interactions to help debug errors. All text, media, and inputs are fully masked before sending."
|
||||
after={
|
||||
<Switch
|
||||
@@ -1341,9 +1390,9 @@ function DiagnosticsAndPrivacy() {
|
||||
);
|
||||
}
|
||||
|
||||
export function General({ requestClose }: Readonly<GeneralProps>) {
|
||||
export function General({ requestBack, requestClose }: Readonly<GeneralProps>) {
|
||||
return (
|
||||
<SettingsSectionPage title="General" requestClose={requestClose}>
|
||||
<SettingsSectionPage title="General" requestBack={requestBack} requestClose={requestClose}>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { ClientConfigProvider } from '$hooks/useClientConfig';
|
||||
import { SettingsLinkBaseUrlSetting } from './SettingsLinkBaseUrlSetting';
|
||||
|
||||
let settingsLinkBaseUrlOverride: string | undefined;
|
||||
const setSettingsLinkBaseUrlOverride = vi.fn();
|
||||
|
||||
vi.mock('$state/hooks/settings', () => ({
|
||||
useSetting: () => [settingsLinkBaseUrlOverride, setSettingsLinkBaseUrlOverride] as const,
|
||||
}));
|
||||
|
||||
vi.mock('$state/settings', () => ({
|
||||
settingsAtom: {},
|
||||
}));
|
||||
|
||||
function renderSetting(settingsLinkBaseUrl = 'https://app.sable.moe') {
|
||||
return render(
|
||||
<ClientConfigProvider value={{ settingsLinkBaseUrl }}>
|
||||
<SettingsLinkBaseUrlSetting />
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
describe('SettingsLinkBaseUrlSetting', () => {
|
||||
beforeEach(() => {
|
||||
settingsLinkBaseUrlOverride = undefined;
|
||||
setSettingsLinkBaseUrlOverride.mockReset();
|
||||
});
|
||||
|
||||
it('shows the configured default in the input and no separate reset button', () => {
|
||||
renderSetting('https://config.example');
|
||||
|
||||
expect(screen.getByRole('textbox', { name: 'Settings link base URL' })).toHaveValue(
|
||||
'https://config.example'
|
||||
);
|
||||
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
||||
expect(screen.queryByRole('button', { name: 'Reset' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('uses an inline reset control to restore the configured default URL', () => {
|
||||
renderSetting('https://config.example');
|
||||
|
||||
fireEvent.change(screen.getByRole('textbox', { name: 'Settings link base URL' }), {
|
||||
target: { value: 'https://override.example' },
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Reset settings link base URL' })
|
||||
).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Reset settings link base URL' }));
|
||||
|
||||
expect(screen.getByRole('textbox', { name: 'Settings link base URL' })).toHaveValue(
|
||||
'https://config.example'
|
||||
);
|
||||
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('clears the override when saving the configured default URL', () => {
|
||||
settingsLinkBaseUrlOverride = 'https://override.example';
|
||||
renderSetting('https://config.example');
|
||||
|
||||
fireEvent.change(screen.getByRole('textbox', { name: 'Settings link base URL' }), {
|
||||
target: { value: 'https://config.example' },
|
||||
});
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
||||
|
||||
expect(setSettingsLinkBaseUrlOverride).toHaveBeenCalledWith(undefined);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
import { ChangeEventHandler, FormEventHandler, useEffect, useMemo, useState } from 'react';
|
||||
import { Box, Button, config, Icon, IconButton, Icons, Input, Text } from 'folds';
|
||||
import { useClientConfig } from '$hooks/useClientConfig';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { getConfiguredSettingsLinkBaseUrl, normalizeSettingsLinkBaseUrl } from '../settingsLink';
|
||||
|
||||
export function SettingsLinkBaseUrlSetting() {
|
||||
const clientConfig = useClientConfig();
|
||||
const [settingsLinkBaseUrlOverride, setSettingsLinkBaseUrlOverride] = useSetting(
|
||||
settingsAtom,
|
||||
'settingsLinkBaseUrlOverride'
|
||||
);
|
||||
const configuredBaseUrl = useMemo(
|
||||
() => getConfiguredSettingsLinkBaseUrl(clientConfig),
|
||||
[clientConfig]
|
||||
);
|
||||
const currentValue =
|
||||
normalizeSettingsLinkBaseUrl(settingsLinkBaseUrlOverride) ?? configuredBaseUrl;
|
||||
const [inputValue, setInputValue] = useState(currentValue);
|
||||
|
||||
useEffect(() => {
|
||||
setInputValue(currentValue);
|
||||
}, [currentValue]);
|
||||
|
||||
const trimmedValue = inputValue.trim();
|
||||
const normalizedInputValue = normalizeSettingsLinkBaseUrl(trimmedValue);
|
||||
const nextOverrideValue =
|
||||
normalizedInputValue && normalizedInputValue !== configuredBaseUrl
|
||||
? normalizedInputValue
|
||||
: undefined;
|
||||
const hasChanges = normalizedInputValue !== currentValue;
|
||||
const isValid = Boolean(normalizedInputValue);
|
||||
|
||||
const handleChange: ChangeEventHandler<HTMLInputElement> = (evt) => {
|
||||
setInputValue(evt.currentTarget.value);
|
||||
};
|
||||
|
||||
const handleSubmit: FormEventHandler<HTMLFormElement> = (evt) => {
|
||||
evt.preventDefault();
|
||||
if (!isValid) return;
|
||||
|
||||
setSettingsLinkBaseUrlOverride(nextOverrideValue);
|
||||
setInputValue(normalizedInputValue ?? configuredBaseUrl);
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
setInputValue(configuredBaseUrl);
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingTile
|
||||
title="Settings Link Base URL"
|
||||
focusId="settings-link-base-url"
|
||||
description={`Copied settings links use this URL. Default: ${configuredBaseUrl}`}
|
||||
>
|
||||
<Box direction="Column" grow="Yes" gap="100">
|
||||
<Box as="form" onSubmit={handleSubmit} gap="200">
|
||||
<Box grow="Yes" direction="Column">
|
||||
<Input
|
||||
aria-label="Settings link base URL"
|
||||
autoComplete="url"
|
||||
name="settingsLinkBaseUrlInput"
|
||||
radii="300"
|
||||
type="url"
|
||||
value={inputValue}
|
||||
variant="Secondary"
|
||||
style={{ paddingRight: config.space.S200 }}
|
||||
onChange={handleChange}
|
||||
after={
|
||||
hasChanges && (
|
||||
<IconButton
|
||||
type="reset"
|
||||
onClick={handleReset}
|
||||
size="300"
|
||||
radii="300"
|
||||
variant="Secondary"
|
||||
aria-label="Reset settings link base URL"
|
||||
title="Reset settings link base URL"
|
||||
>
|
||||
<Icon src={Icons.Cross} size="100" />
|
||||
</IconButton>
|
||||
)
|
||||
}
|
||||
/>
|
||||
</Box>
|
||||
<Button
|
||||
disabled={!hasChanges || !isValid}
|
||||
fill={hasChanges && isValid ? 'Solid' : 'Soft'}
|
||||
outlined
|
||||
radii="300"
|
||||
size="400"
|
||||
type="submit"
|
||||
variant={hasChanges && isValid ? 'Success' : 'Secondary'}
|
||||
>
|
||||
<Text size="B400">Save</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
{!isValid && (
|
||||
<Text size="T200" priority="400">
|
||||
Enter a full `http://` or `https://` URL.
|
||||
</Text>
|
||||
)}
|
||||
</SettingTile>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './Settings';
|
||||
export * from './SettingsRoute';
|
||||
export * from './settingsLink';
|
||||
export * from './routes';
|
||||
export * from './useOpenSettings';
|
||||
@@ -107,14 +107,16 @@ function ShortcutRow({ keys, description }: ShortcutEntry) {
|
||||
}
|
||||
|
||||
type KeyboardShortcutsProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function KeyboardShortcuts({ requestClose }: KeyboardShortcutsProps) {
|
||||
export function KeyboardShortcuts({ requestBack, requestClose }: KeyboardShortcutsProps) {
|
||||
return (
|
||||
<SettingsSectionPage
|
||||
title="Keyboard Shortcuts"
|
||||
titleAs="h1"
|
||||
actionLabel="Close keyboard shortcuts"
|
||||
requestBack={requestBack}
|
||||
requestClose={requestClose}
|
||||
>
|
||||
<Box grow="Yes">
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { To } from 'react-router-dom';
|
||||
import { getHomePath } from '$pages/pathUtils';
|
||||
|
||||
export type SettingsStoredLocation = {
|
||||
pathname: string;
|
||||
search: string;
|
||||
hash: string;
|
||||
state?: unknown;
|
||||
key?: string;
|
||||
};
|
||||
|
||||
export type SettingsRouteState = {
|
||||
backgroundLocation?: SettingsStoredLocation;
|
||||
redirectedFromDesktopRoot?: boolean;
|
||||
};
|
||||
|
||||
export function getSettingsCloseTarget(routeState: SettingsRouteState | null | undefined): {
|
||||
to: To;
|
||||
state?: unknown;
|
||||
} {
|
||||
const backgroundLocation = routeState?.backgroundLocation;
|
||||
if (!backgroundLocation) {
|
||||
return { to: getHomePath() };
|
||||
}
|
||||
|
||||
return {
|
||||
to: {
|
||||
pathname: backgroundLocation.pathname,
|
||||
search: backgroundLocation.search,
|
||||
hash: backgroundLocation.hash,
|
||||
},
|
||||
state: backgroundLocation.state,
|
||||
};
|
||||
}
|
||||
@@ -109,6 +109,7 @@ export function AllMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Direct Messages"
|
||||
focusId="direct-messages"
|
||||
description="Includes 1-to-1, group DMs, and bridged conversations."
|
||||
after={<AllMessagesModeSwitcher pushRules={pushRules} ruleId={RuleId.DM} oneToOne />}
|
||||
/>
|
||||
@@ -121,6 +122,7 @@ export function AllMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Direct Messages (Encrypted)"
|
||||
focusId="direct-messages-encrypted"
|
||||
description="Includes 1-to-1, group DMs, and bridged conversations."
|
||||
after={
|
||||
<AllMessagesModeSwitcher
|
||||
@@ -140,6 +142,7 @@ export function AllMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Rooms"
|
||||
focusId="rooms"
|
||||
after={<AllMessagesModeSwitcher pushRules={pushRules} ruleId={RuleId.Message} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
@@ -151,6 +154,7 @@ export function AllMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Rooms (Encrypted)"
|
||||
focusId="rooms-encrypted"
|
||||
after={
|
||||
<AllMessagesModeSwitcher
|
||||
pushRules={pushRules}
|
||||
|
||||
@@ -113,6 +113,7 @@ export function DeregisterAllPushersSetting() {
|
||||
|
||||
<SettingTile
|
||||
title="Reset All Push Notifications"
|
||||
focusId="reset-all-push-notifications"
|
||||
description={
|
||||
<>
|
||||
This will remove push notifications from all your sessions/devices.
|
||||
|
||||
@@ -6,6 +6,7 @@ import { AccountDataEvent } from '$types/matrix/accountData';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { toSettingsFocusIdPart } from '$features/settings/settingsLink';
|
||||
import {
|
||||
getNotificationModeActions,
|
||||
NotificationMode,
|
||||
@@ -183,6 +184,7 @@ export function KeywordMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Select Keyword"
|
||||
focusId="select-keyword"
|
||||
description="Set a notification preference for message containing given keyword."
|
||||
>
|
||||
<KeywordInput />
|
||||
@@ -198,6 +200,9 @@ export function KeywordMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title={`"${pushRule.pattern}"`}
|
||||
focusId={`keyword-${toSettingsFocusIdPart(
|
||||
pushRule.pattern ?? pushRule.rule_id ?? 'custom-keyword'
|
||||
)}`}
|
||||
before={<KeywordCross pushRule={pushRule} />}
|
||||
after={<KeywordModeSwitcher pushRule={pushRule} />}
|
||||
/>
|
||||
|
||||
@@ -7,11 +7,16 @@ import { SpecialMessagesNotifications } from './SpecialMessages';
|
||||
import { KeywordMessagesNotifications } from './KeywordMessages';
|
||||
|
||||
type NotificationsProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
export function Notifications({ requestClose }: NotificationsProps) {
|
||||
export function Notifications({ requestBack, requestClose }: NotificationsProps) {
|
||||
return (
|
||||
<SettingsSectionPage title="Notifications" requestClose={requestClose}>
|
||||
<SettingsSectionPage
|
||||
title="Notifications"
|
||||
requestBack={requestBack}
|
||||
requestClose={requestClose}
|
||||
>
|
||||
<Box grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
|
||||
@@ -146,6 +146,7 @@ export function SpecialMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title={`Mention User ID ("${userId}")`}
|
||||
focusId="mention-user-id"
|
||||
after={
|
||||
<MentionModeSwitcher
|
||||
pushRules={pushRules}
|
||||
@@ -163,6 +164,7 @@ export function SpecialMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title={`Contains Displayname ${displayName ? `("${displayName}")` : ''}`}
|
||||
focusId="contains-display-name"
|
||||
after={
|
||||
<MentionModeSwitcher
|
||||
pushRules={pushRules}
|
||||
@@ -180,6 +182,7 @@ export function SpecialMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title={`Contains Username ("${getMxIdLocalPart(userId)}")`}
|
||||
focusId="contains-username"
|
||||
after={
|
||||
<MentionModeSwitcher
|
||||
pushRules={pushRules}
|
||||
@@ -197,6 +200,7 @@ export function SpecialMessagesNotifications() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Mention @room"
|
||||
focusId="mention-room"
|
||||
description="Only triggers if the sender has permission to notify the whole room."
|
||||
after={
|
||||
intentionalMentions ? (
|
||||
|
||||
@@ -65,6 +65,7 @@ function EmailNotification() {
|
||||
return (
|
||||
<SettingTile
|
||||
title="Email Notification"
|
||||
focusId="email-notification"
|
||||
description={
|
||||
<>
|
||||
{result && !result.email && (
|
||||
@@ -140,6 +141,7 @@ function WebPushNotificationSetting() {
|
||||
return (
|
||||
<SettingTile
|
||||
title="Background Push Notifications"
|
||||
focusId="background-push-notifications"
|
||||
description={
|
||||
browserPermission === 'denied' ? (
|
||||
<Text as="span" style={{ color: color.Critical.Main }} size="T200">
|
||||
@@ -237,6 +239,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="In-App Notifications"
|
||||
focusId="in-app-notifications"
|
||||
description="Show a notification banner inside the app when a message arrives."
|
||||
after={<Switch value={showInAppNotifs} onChange={setShowInAppNotifs} />}
|
||||
/>
|
||||
@@ -260,6 +263,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="System Notifications"
|
||||
focusId="system-notifications"
|
||||
description="Show an OS-level notification banner when a message arrives while the app is open."
|
||||
after={<Switch value={showSystemNotifs} onChange={setShowSystemNotifs} />}
|
||||
/>
|
||||
@@ -273,6 +277,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="In-App Notification Sound"
|
||||
focusId="in-app-notification-sound"
|
||||
description="Play a sound inside the app when a new message arrives."
|
||||
after={<Switch value={isNotificationSounds} onChange={setIsNotificationSounds} />}
|
||||
/>
|
||||
@@ -285,6 +290,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Show Message Content"
|
||||
focusId="show-message-content"
|
||||
description="Include message text in notification bodies."
|
||||
after={<Switch value={showMessageContent} onChange={setShowMessageContent} />}
|
||||
/>
|
||||
@@ -297,6 +303,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Show Encrypted Message Content"
|
||||
focusId="show-encrypted-message-content"
|
||||
description="Allow message text from encrypted rooms in notification bodies. May not work on some platforms due to technical limitations."
|
||||
after={
|
||||
<Switch
|
||||
@@ -315,6 +322,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Clear Notifications When Read Elsewhere"
|
||||
focusId="clear-notifications-when-read-elsewhere"
|
||||
description="Automatically dismiss notifications on this device when you read messages on another device."
|
||||
after={<Switch value={clearNotificationsOnRead} onChange={setClearNotificationsOnRead} />}
|
||||
/>
|
||||
@@ -351,6 +359,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Favicon Dot: Mentions Only"
|
||||
focusId="favicon-dot-mentions-only"
|
||||
description="Only change the browser tab favicon when you have mentions or keywords. Unreads without mentions won't affect the favicon."
|
||||
after={
|
||||
<Switch
|
||||
@@ -369,6 +378,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Show Room Counts"
|
||||
focusId="show-room-counts"
|
||||
description="Displays a number for unread activity in Rooms and Spaces."
|
||||
after={
|
||||
<Switch variant="Primary" value={showUnreadCounts} onChange={setShowUnreadCounts} />
|
||||
@@ -383,6 +393,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Show DM Counts"
|
||||
focusId="show-dm-counts"
|
||||
description="Displays a number for unread Direct Messages."
|
||||
after={
|
||||
<Switch variant="Primary" value={badgeCountDMsOnly} onChange={setBadgeCountDMsOnly} />
|
||||
@@ -397,6 +408,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Show Mention Counts"
|
||||
focusId="show-mention-counts"
|
||||
description="Displays a number for mentions and keyword alerts."
|
||||
after={<Switch variant="Primary" value={showPingCounts} onChange={setShowPingCounts} />}
|
||||
/>
|
||||
@@ -409,6 +421,7 @@ export function SystemNotification() {
|
||||
>
|
||||
<SettingTile
|
||||
title="Highlight Mentions"
|
||||
focusId="highlight-mentions"
|
||||
description="Highlight the full background message when it contains a mention/keyword."
|
||||
after={
|
||||
<Switch variant="Primary" value={highlightMentions} onChange={setHighlightMentions} />
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { readFileSync, readdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const getSettingsFiles = (dir: string): string[] =>
|
||||
readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
||||
const filePath = join(dir, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
return getSettingsFiles(filePath);
|
||||
}
|
||||
|
||||
if (!entry.isFile() || !filePath.endsWith('.tsx') || filePath.endsWith('.test.tsx')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [filePath];
|
||||
});
|
||||
|
||||
describe('settings tile focus coverage', () => {
|
||||
it('requires every settings SettingTile to declare a focusId', () => {
|
||||
const offenders = getSettingsFiles('src/app/features/settings').flatMap((file) => {
|
||||
const source = readFileSync(file, 'utf8');
|
||||
const matches = [...source.matchAll(/<SettingTile\b(?![^>]*\bfocusId=)/g)];
|
||||
|
||||
return matches.map(() => file);
|
||||
});
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
DEFAULT_SETTINGS_LINK_BASE_URL,
|
||||
buildSettingsPermalink,
|
||||
getEffectiveSettingsLinkBaseUrl,
|
||||
parseSettingsPermalink,
|
||||
toSettingsFocusIdPart,
|
||||
} from './settingsLink';
|
||||
|
||||
describe('settingsLink', () => {
|
||||
it('builds settings permalinks for plain and hash-router base urls', () => {
|
||||
expect(
|
||||
buildSettingsPermalink('https://app.example', 'appearance', 'message-link-preview')
|
||||
).toBe('https://app.example/settings/appearance/?focus=message-link-preview');
|
||||
expect(
|
||||
buildSettingsPermalink('https://app.example/#/app', 'appearance', 'message-link-preview')
|
||||
).toBe('https://app.example/#/app/settings/appearance/?focus=message-link-preview');
|
||||
});
|
||||
|
||||
it('resolves the settings link base URL from built-in default, config, and override', () => {
|
||||
expect(getEffectiveSettingsLinkBaseUrl({}, undefined)).toBe(DEFAULT_SETTINGS_LINK_BASE_URL);
|
||||
expect(getEffectiveSettingsLinkBaseUrl({}, true as never)).toBe(DEFAULT_SETTINGS_LINK_BASE_URL);
|
||||
expect(
|
||||
getEffectiveSettingsLinkBaseUrl({ settingsLinkBaseUrl: 'https://config.example/' })
|
||||
).toBe('https://config.example');
|
||||
expect(
|
||||
getEffectiveSettingsLinkBaseUrl(
|
||||
{ settingsLinkBaseUrl: 'https://config.example' },
|
||||
'https://override.example/'
|
||||
)
|
||||
).toBe('https://override.example');
|
||||
});
|
||||
|
||||
it('parses settings permalinks from the same app origin only', () => {
|
||||
expect(
|
||||
parseSettingsPermalink(
|
||||
'https://app.example',
|
||||
'https://app.example/settings/appearance/?focus=message-link-preview'
|
||||
)
|
||||
).toEqual({ section: 'appearance', focus: 'message-link-preview' });
|
||||
|
||||
expect(
|
||||
parseSettingsPermalink('https://app.example', 'https://other.example/settings/appearance/')
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
parseSettingsPermalink('https://app.example', 'https://app.example/home/')
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('rejects a same-origin hash permalink that does not match the configured app base', () => {
|
||||
expect(
|
||||
parseSettingsPermalink(
|
||||
'https://app.example/#/app',
|
||||
'https://app.example/#/wrong/settings/appearance/?focus=message-link-preview'
|
||||
)
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('rejects a same-origin hash permalink that only shares the configured base as a prefix', () => {
|
||||
expect(
|
||||
parseSettingsPermalink(
|
||||
'https://app.example/#/app',
|
||||
'https://app.example/#/ap/settings/appearance/?focus=message-link-preview'
|
||||
)
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('normalizes focus id parts', () => {
|
||||
expect(toSettingsFocusIdPart('@alice:example.org')).toBe('alice-example-org');
|
||||
expect(toSettingsFocusIdPart('DEVICE-123')).toBe('device-123');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
import type { ClientConfig } from '$hooks/useClientConfig';
|
||||
import { getAppPathFromHref, getSettingsPath, withOriginBaseUrl } from '$pages/pathUtils';
|
||||
import { isSettingsSectionId, type SettingsSectionId } from './routes';
|
||||
|
||||
export type SettingsPermalink = {
|
||||
section: SettingsSectionId;
|
||||
focus?: string;
|
||||
};
|
||||
|
||||
export const DEFAULT_SETTINGS_LINK_BASE_URL = 'https://app.sable.moe';
|
||||
|
||||
export const normalizeSettingsLinkBaseUrl = (value?: string | null): string | undefined => {
|
||||
if (typeof value !== 'string') return undefined;
|
||||
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return undefined;
|
||||
|
||||
try {
|
||||
const url = new URL(trimmed);
|
||||
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return url.toString().replace(/\/+$/, '');
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const getConfiguredSettingsLinkBaseUrl = (
|
||||
clientConfig: Pick<ClientConfig, 'settingsLinkBaseUrl'>
|
||||
): string =>
|
||||
normalizeSettingsLinkBaseUrl(clientConfig.settingsLinkBaseUrl) ?? DEFAULT_SETTINGS_LINK_BASE_URL;
|
||||
|
||||
export const getEffectiveSettingsLinkBaseUrl = (
|
||||
clientConfig: Pick<ClientConfig, 'settingsLinkBaseUrl'>,
|
||||
override?: string
|
||||
): string =>
|
||||
normalizeSettingsLinkBaseUrl(override) ?? getConfiguredSettingsLinkBaseUrl(clientConfig);
|
||||
|
||||
export const buildSettingsPermalink = (
|
||||
baseUrl: string,
|
||||
section: SettingsSectionId,
|
||||
focus?: string
|
||||
): string => withOriginBaseUrl(baseUrl, getSettingsPath(section, focus));
|
||||
|
||||
export const parseSettingsPermalink = (
|
||||
baseUrl: string,
|
||||
href: string
|
||||
): SettingsPermalink | undefined => {
|
||||
try {
|
||||
const base = new URL(baseUrl);
|
||||
const target = new URL(href);
|
||||
|
||||
if (base.origin !== target.origin) return undefined;
|
||||
|
||||
if (base.hash) {
|
||||
const baseHash = base.hash.replace(/\/+$/, '');
|
||||
if (!(target.hash === baseHash || target.hash.startsWith(`${baseHash}/`))) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const appPath = getAppPathFromHref(baseUrl, href);
|
||||
if (!appPath.startsWith('/settings/')) return undefined;
|
||||
|
||||
const [pathname, search = ''] = appPath.split('?');
|
||||
const sectionMatch = pathname.match(/^\/settings\/([^/]+)\/$/);
|
||||
if (!sectionMatch) return undefined;
|
||||
|
||||
const section = sectionMatch[1];
|
||||
if (!isSettingsSectionId(section)) return undefined;
|
||||
|
||||
const focus = new URLSearchParams(search).get('focus') ?? undefined;
|
||||
|
||||
return { section, focus };
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const toSettingsFocusIdPart = (value: string): string =>
|
||||
value
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
@@ -1,28 +1,14 @@
|
||||
import { keyframes, style } from '@vanilla-extract/css';
|
||||
import { color, config } from 'folds';
|
||||
import { style } from '@vanilla-extract/css';
|
||||
import { config } from 'folds';
|
||||
import { messageJumpHighlight } from '$components/message/layout/layout.css';
|
||||
|
||||
export const SequenceCardStyle = style({
|
||||
padding: config.space.S300,
|
||||
});
|
||||
|
||||
const focusPulse = keyframes({
|
||||
'0%': {
|
||||
backgroundColor: 'transparent',
|
||||
boxShadow: `inset 0 0 0 ${config.borderWidth.B300} ${color.Primary.ContainerLine}`,
|
||||
},
|
||||
'20%': {
|
||||
backgroundColor: `color-mix(in srgb, ${color.Primary.Container} 20%, transparent)`,
|
||||
},
|
||||
'50%': {
|
||||
backgroundColor: `color-mix(in srgb, ${color.Primary.Container} 8%, transparent)`,
|
||||
},
|
||||
'100%': {
|
||||
backgroundColor: 'transparent',
|
||||
boxShadow: `inset 0 0 0 ${config.borderWidth.B300} ${color.Primary.ContainerLine}`,
|
||||
},
|
||||
export const settingsHeader = style({
|
||||
paddingLeft: config.space.S300,
|
||||
paddingRight: config.space.S200,
|
||||
});
|
||||
|
||||
export const focusedSettingTile = style({
|
||||
borderRadius: config.radii.R400,
|
||||
animation: `${focusPulse} 3s ease-in-out 1`,
|
||||
});
|
||||
export const focusedSettingTile = messageJumpHighlight;
|
||||
@@ -2,6 +2,10 @@ import { useEffect, useRef } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { focusedSettingTile } from './styles.css';
|
||||
|
||||
const focusedSettingTileClasses = focusedSettingTile.split(' ').filter(Boolean);
|
||||
const getHighlightTarget = (target: HTMLElement): HTMLElement =>
|
||||
target.closest<HTMLElement>('[data-sequence-card="true"]') ?? target.parentElement ?? target;
|
||||
|
||||
export function useSettingsFocus() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const focusId = searchParams.get('focus');
|
||||
@@ -14,7 +18,7 @@ export function useSettingsFocus() {
|
||||
window.clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = undefined;
|
||||
}
|
||||
activeTargetRef.current?.classList.remove(focusedSettingTile);
|
||||
activeTargetRef.current?.classList.remove(...focusedSettingTileClasses);
|
||||
activeTargetRef.current = null;
|
||||
},
|
||||
[]
|
||||
@@ -27,8 +31,10 @@ export function useSettingsFocus() {
|
||||
document.querySelector<HTMLElement>(`[data-settings-focus="${focusId}"]`);
|
||||
|
||||
if (target) {
|
||||
if (activeTargetRef.current && activeTargetRef.current !== target) {
|
||||
activeTargetRef.current.classList.remove(focusedSettingTile);
|
||||
const highlightTarget = getHighlightTarget(target);
|
||||
|
||||
if (activeTargetRef.current && activeTargetRef.current !== highlightTarget) {
|
||||
activeTargetRef.current.classList.remove(...focusedSettingTileClasses);
|
||||
}
|
||||
if (timeoutRef.current !== undefined) {
|
||||
window.clearTimeout(timeoutRef.current);
|
||||
@@ -36,12 +42,12 @@ export function useSettingsFocus() {
|
||||
}
|
||||
|
||||
target.scrollIntoView?.({ block: 'center', behavior: 'smooth' });
|
||||
target.classList.add(focusedSettingTile);
|
||||
activeTargetRef.current = target;
|
||||
highlightTarget.classList.add(...focusedSettingTileClasses);
|
||||
activeTargetRef.current = highlightTarget;
|
||||
|
||||
timeoutRef.current = window.setTimeout(() => {
|
||||
target.classList.remove(focusedSettingTile);
|
||||
if (activeTargetRef.current === target) {
|
||||
highlightTarget.classList.remove(...focusedSettingTileClasses);
|
||||
if (activeTargetRef.current === highlightTarget) {
|
||||
activeTargetRef.current = null;
|
||||
}
|
||||
timeoutRef.current = undefined;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useClientConfig } from '$hooks/useClientConfig';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { getEffectiveSettingsLinkBaseUrl } from './settingsLink';
|
||||
|
||||
export const useSettingsLinkBaseUrl = (): string => {
|
||||
const clientConfig = useClientConfig();
|
||||
const [settingsLinkBaseUrlOverride] = useSetting(settingsAtom, 'settingsLinkBaseUrlOverride');
|
||||
|
||||
return useMemo(
|
||||
() => getEffectiveSettingsLinkBaseUrl(clientConfig, settingsLinkBaseUrlOverride),
|
||||
[clientConfig, settingsLinkBaseUrlOverride]
|
||||
);
|
||||
};
|
||||
@@ -42,6 +42,7 @@ export type ClientConfig = {
|
||||
hashRouter?: HashRouterConfig;
|
||||
|
||||
matrixToBaseUrl?: string;
|
||||
settingsLinkBaseUrl?: string;
|
||||
};
|
||||
|
||||
const ClientConfigContext = createContext<ClientConfig | null>(null);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { render, fireEvent, renderHook } from '@testing-library/react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { useMentionClickHandler } from './useMentionClickHandler';
|
||||
|
||||
const { mockOpenSettings } = vi.hoisted(() => ({
|
||||
mockOpenSettings: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useMatrixClient', () => ({
|
||||
useMatrixClient: () => ({ getRoom: vi.fn() }),
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useRoomNavigate', () => ({
|
||||
useRoomNavigate: () => ({ navigateRoom: vi.fn(), navigateSpace: vi.fn() }),
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useSpace', () => ({
|
||||
useSpaceOptionally: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock('$state/hooks/userRoomProfile', () => ({
|
||||
useOpenUserRoomProfile: () => vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('$features/settings/useOpenSettings', () => ({
|
||||
useOpenSettings: () => mockOpenSettings,
|
||||
}));
|
||||
|
||||
vi.mock('react-router-dom', () => ({
|
||||
useNavigate: () => vi.fn(),
|
||||
}));
|
||||
|
||||
function Wrapper({ children }: { children: ReactNode }) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
describe('useMentionClickHandler', () => {
|
||||
beforeEach(() => {
|
||||
mockOpenSettings.mockReset();
|
||||
});
|
||||
|
||||
it('routes settings permalinks through openSettings with section and focus', () => {
|
||||
const { result } = renderHook(() => useMentionClickHandler('!room:example.org'), {
|
||||
wrapper: Wrapper,
|
||||
});
|
||||
|
||||
const { getByRole } = render(
|
||||
<button
|
||||
type="button"
|
||||
data-settings-link-section="appearance"
|
||||
data-settings-link-focus="message-link-preview"
|
||||
onClick={result.current}
|
||||
>
|
||||
Open settings link
|
||||
</button>
|
||||
);
|
||||
|
||||
fireEvent.click(getByRole('button', { name: 'Open settings link' }));
|
||||
|
||||
expect(mockOpenSettings).toHaveBeenCalledWith('appearance', 'message-link-preview');
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,8 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { isRoomId, isUserId } from '$utils/matrix';
|
||||
import { getHomeRoomPath, withSearchParam } from '$pages/pathUtils';
|
||||
import { RoomSearchParams } from '$pages/paths';
|
||||
import { isSettingsSectionId } from '$features/settings/routes';
|
||||
import { useOpenSettings } from '$features/settings/useOpenSettings';
|
||||
import { useOpenUserRoomProfile } from '$state/hooks/userRoomProfile';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { useRoomNavigate } from './useRoomNavigate';
|
||||
@@ -14,12 +16,20 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
|
||||
const navigate = useNavigate();
|
||||
const openProfile = useOpenUserRoomProfile();
|
||||
const space = useSpaceOptionally();
|
||||
const openSettings = useOpenSettings();
|
||||
|
||||
const handleClick: ReactEventHandler<HTMLElement> = useCallback(
|
||||
(evt) => {
|
||||
evt.stopPropagation();
|
||||
evt.preventDefault();
|
||||
const target = evt.currentTarget;
|
||||
const settingsSection = target.getAttribute('data-settings-link-section') || undefined;
|
||||
if (isSettingsSectionId(settingsSection)) {
|
||||
const settingsFocus = target.getAttribute('data-settings-link-focus') || undefined;
|
||||
openSettings(settingsSection, settingsFocus);
|
||||
return;
|
||||
}
|
||||
|
||||
const mentionId = target.getAttribute('data-mention-id');
|
||||
if (typeof mentionId !== 'string') return;
|
||||
|
||||
@@ -40,7 +50,7 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
|
||||
|
||||
navigate(viaServers ? withSearchParam<RoomSearchParams>(path, { viaServers }) : path);
|
||||
},
|
||||
[mx, navigate, navigateRoom, navigateSpace, roomId, space, openProfile]
|
||||
[mx, navigate, navigateRoom, navigateSpace, openProfile, openSettings, roomId, space]
|
||||
);
|
||||
|
||||
return handleClick;
|
||||
|
||||
+13
-2
@@ -1,8 +1,8 @@
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { Provider as JotaiProvider } from 'jotai';
|
||||
import { OverlayContainerProvider, PopOutContainerProvider, TooltipContainerProvider } from 'folds';
|
||||
import { RouterProvider } from 'react-router-dom';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||
import * as Sentry from '@sentry/react';
|
||||
|
||||
import { ClientConfigLoader } from '$components/ClientConfigLoader';
|
||||
@@ -14,12 +14,19 @@ import { ErrorPage } from '$components/DefaultErrorPage';
|
||||
import { ConfigConfigError, ConfigConfigLoading } from './ConfigConfig';
|
||||
import { FeatureCheck } from './FeatureCheck';
|
||||
import { createRouter } from './Router';
|
||||
import { isReactQueryDevtoolsEnabled } from './reactQueryDevtoolsGate';
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const ReactQueryDevtools = lazy(async () => {
|
||||
const { ReactQueryDevtools: Devtools } = await import('@tanstack/react-query-devtools');
|
||||
|
||||
return { default: Devtools };
|
||||
});
|
||||
|
||||
function App() {
|
||||
const screenSize = useScreenSize();
|
||||
useCompositionEndTracking();
|
||||
const reactQueryDevtoolsEnabled = isReactQueryDevtoolsEnabled();
|
||||
|
||||
const portalContainer = document.getElementById('portalContainer') ?? undefined;
|
||||
|
||||
@@ -51,7 +58,11 @@ function App() {
|
||||
<JotaiProvider>
|
||||
<RouterProvider router={createRouter(clientConfig, screenSize)} />
|
||||
</JotaiProvider>
|
||||
<ReactQueryDevtools initialIsOpen={false} />
|
||||
{reactQueryDevtoolsEnabled && (
|
||||
<Suspense fallback={null}>
|
||||
<ReactQueryDevtools initialIsOpen={false} />
|
||||
</Suspense>
|
||||
)}
|
||||
</QueryClientProvider>
|
||||
</ClientConfigProvider>
|
||||
);
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { Box } from 'folds';
|
||||
import { matchPath, useLocation } from 'react-router-dom';
|
||||
import { useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
import { SETTINGS_PATH } from '../paths';
|
||||
import { isShallowSettingsRoute } from './ClientRouteOutlet';
|
||||
|
||||
type ClientLayoutProps = {
|
||||
nav: ReactNode;
|
||||
children: ReactNode;
|
||||
};
|
||||
export function ClientLayout({ nav, children }: ClientLayoutProps) {
|
||||
const location = useLocation();
|
||||
const screenSize = useScreenSizeContext();
|
||||
const fullPageSettings =
|
||||
Boolean(matchPath(SETTINGS_PATH, location.pathname)) &&
|
||||
!isShallowSettingsRoute(location.pathname, location.state, screenSize);
|
||||
|
||||
return (
|
||||
<Box grow="Yes">
|
||||
<Box shrink="No">{nav}</Box>
|
||||
{!fullPageSettings && <Box shrink="No">{nav}</Box>}
|
||||
<Box grow="Yes">{children}</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -39,6 +39,7 @@ import { getMxIdLocalPart, mxcUrlToHttp } from '$utils/matrix';
|
||||
import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
|
||||
import { useInboxNotificationsSelected } from '$hooks/router/useInbox';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { registrationAtom } from '$state/serviceWorkerRegistration';
|
||||
import { pendingNotificationAtom, inAppBannerAtom, activeSessionIdAtom } from '$state/sessions';
|
||||
import {
|
||||
@@ -242,6 +243,7 @@ function MessageNotifications() {
|
||||
const clientStartTimeRef = useRef(Date.now());
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const appBaseUrl = useSettingsLinkBaseUrl();
|
||||
const [showNotifications] = useSetting(settingsAtom, 'useInAppNotifications');
|
||||
const [showSystemNotifications] = useSetting(settingsAtom, 'useSystemNotifications');
|
||||
const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications');
|
||||
@@ -474,6 +476,7 @@ function MessageNotifications() {
|
||||
content.formatted_body
|
||||
) {
|
||||
const htmlParserOpts = getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl: appBaseUrl,
|
||||
linkifyOpts: LINKIFY_OPTS,
|
||||
useAuthentication,
|
||||
nicknames: nicknamesRef.current,
|
||||
@@ -532,6 +535,7 @@ function MessageNotifications() {
|
||||
setInAppBanner,
|
||||
setPending,
|
||||
selectedRoomId,
|
||||
appBaseUrl,
|
||||
useAuthentication,
|
||||
]);
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ import { UserAvatar } from '$components/user-avatar';
|
||||
import { EncryptedContent } from '$features/room/message';
|
||||
import { useMentionClickHandler } from '$hooks/useMentionClickHandler';
|
||||
import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
import { BackRouteHandler } from '$components/BackRouteHandler';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
@@ -204,6 +205,7 @@ const useNotificationTimeline = (
|
||||
|
||||
type RoomNotificationsGroupProps = {
|
||||
room: Room;
|
||||
appBaseUrl: string;
|
||||
notifications: INotification[];
|
||||
mediaAutoLoad?: boolean;
|
||||
urlPreview?: boolean;
|
||||
@@ -215,6 +217,7 @@ type RoomNotificationsGroupProps = {
|
||||
};
|
||||
function RoomNotificationsGroupComp({
|
||||
room,
|
||||
appBaseUrl,
|
||||
notifications,
|
||||
mediaAutoLoad,
|
||||
urlPreview,
|
||||
@@ -245,28 +248,41 @@ function RoomNotificationsGroupComp({
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
render: factoryRenderLinkifyWithMention(
|
||||
appBaseUrl,
|
||||
(href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
),
|
||||
mentionClickHandler
|
||||
),
|
||||
}),
|
||||
[mx, room, mentionClickHandler, nicknames]
|
||||
[appBaseUrl, mx, room, mentionClickHandler, nicknames]
|
||||
);
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, room.roomId, {
|
||||
settingsLinkBaseUrl: appBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
handleMentionClick: mentionClickHandler,
|
||||
nicknames,
|
||||
}),
|
||||
[mx, room, linkifyOpts, mentionClickHandler, spoilerClickHandler, useAuthentication, nicknames]
|
||||
[
|
||||
appBaseUrl,
|
||||
mx,
|
||||
room,
|
||||
linkifyOpts,
|
||||
mentionClickHandler,
|
||||
spoilerClickHandler,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
]
|
||||
);
|
||||
|
||||
const renderMatrixEvent = useMatrixEventRenderer<[IRoomEvent, string, GetContentCallback]>(
|
||||
@@ -582,6 +598,7 @@ export function Notifications() {
|
||||
const [dateFormatString] = useSetting(settingsAtom, 'dateFormatString');
|
||||
const screenSize = useScreenSizeContext();
|
||||
const mDirects = useAtomValue(mDirectAtom);
|
||||
const appBaseUrl = useSettingsLinkBaseUrl();
|
||||
|
||||
const { navigateRoom } = useRoomNavigate();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
@@ -726,6 +743,7 @@ export function Notifications() {
|
||||
>
|
||||
<RoomNotificationsGroupComp
|
||||
room={groupRoom}
|
||||
appBaseUrl={appBaseUrl}
|
||||
notifications={group.notifications}
|
||||
mediaAutoLoad={mediaAutoLoad}
|
||||
urlPreview={urlPreview}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
isReactQueryDevtoolsEnabled,
|
||||
REACT_QUERY_DEVTOOLS_LOCAL_STORAGE_KEY,
|
||||
} from './reactQueryDevtoolsGate';
|
||||
|
||||
describe('reactQueryDevtoolsGate', () => {
|
||||
afterEach(() => {
|
||||
localStorage.clear();
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it('is disabled by default even in development', () => {
|
||||
vi.stubEnv('VITE_ENABLE_REACT_QUERY_DEVTOOLS', 'false');
|
||||
|
||||
expect(isReactQueryDevtoolsEnabled()).toBe(false);
|
||||
});
|
||||
|
||||
it('is enabled by the env variable', () => {
|
||||
vi.stubEnv('VITE_ENABLE_REACT_QUERY_DEVTOOLS', 'true');
|
||||
|
||||
expect(isReactQueryDevtoolsEnabled()).toBe(true);
|
||||
});
|
||||
|
||||
it('is enabled by the local storage flag', () => {
|
||||
vi.stubEnv('VITE_ENABLE_REACT_QUERY_DEVTOOLS', 'false');
|
||||
localStorage.setItem(REACT_QUERY_DEVTOOLS_LOCAL_STORAGE_KEY, '1');
|
||||
|
||||
expect(isReactQueryDevtoolsEnabled()).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
export const REACT_QUERY_DEVTOOLS_LOCAL_STORAGE_KEY = 'sable_react_query_devtools';
|
||||
|
||||
export const isReactQueryDevtoolsEnabled = (): boolean =>
|
||||
import.meta.env.VITE_ENABLE_REACT_QUERY_DEVTOOLS === 'true' ||
|
||||
localStorage.getItem(REACT_QUERY_DEVTOOLS_LOCAL_STORAGE_KEY) === '1';
|
||||
@@ -0,0 +1,98 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import parse from 'html-react-parser';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import * as customHtmlCss from '$styles/CustomHtml.css';
|
||||
import {
|
||||
LINKIFY_OPTS,
|
||||
factoryRenderLinkifyWithMention,
|
||||
getReactCustomHtmlParser,
|
||||
makeMentionCustomProps,
|
||||
renderMatrixMention,
|
||||
} from './react-custom-html-parser';
|
||||
|
||||
const settingsLinkBaseUrl = 'https://app.example';
|
||||
|
||||
const mockMx = {
|
||||
getUserId: () => '@alice:example.org',
|
||||
getRoom: () => undefined,
|
||||
};
|
||||
|
||||
function Subject({ body }: { body: string }) {
|
||||
const options = getReactCustomHtmlParser(mockMx as never, undefined, {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts: LINKIFY_OPTS,
|
||||
handleMentionClick: undefined,
|
||||
});
|
||||
|
||||
return <div>{parse(body, options)}</div>;
|
||||
}
|
||||
|
||||
describe('react custom html parser', () => {
|
||||
it('renders same-origin raw settings permalinks as mention-style chips through the factory link render path', () => {
|
||||
const renderLink = factoryRenderLinkifyWithMention(
|
||||
settingsLinkBaseUrl,
|
||||
() => undefined,
|
||||
undefined
|
||||
) as (ir: never) => JSX.Element;
|
||||
|
||||
render(
|
||||
<div>
|
||||
{renderLink({
|
||||
tagName: 'a',
|
||||
attributes: {
|
||||
href: 'https://app.example/settings/appearance/?focus=message-link-preview',
|
||||
},
|
||||
content: 'https://app.example/settings/appearance/?focus=message-link-preview',
|
||||
} as never)}
|
||||
</div>
|
||||
);
|
||||
|
||||
const link = screen.getByRole('link', { name: 'Appearance / Message Link Preview' });
|
||||
expect(link).toHaveAttribute('data-settings-link-section', 'appearance');
|
||||
expect(link).toHaveAttribute('data-settings-link-focus', 'message-link-preview');
|
||||
expect(link.className).toContain(customHtmlCss.Mention({}));
|
||||
expect(link.className).toContain(customHtmlCss.SettingsMention);
|
||||
expect(link).not.toHaveTextContent('Settings:');
|
||||
});
|
||||
|
||||
it('renders same-origin settings permalinks as internal app links with settings metadata', () => {
|
||||
render(
|
||||
<Subject body='<a href="https://app.example/settings/appearance/?focus=message-link-preview">Appearance</a>' />
|
||||
);
|
||||
|
||||
const link = screen.getByRole('link', { name: 'Appearance' });
|
||||
expect(link).toHaveAttribute(
|
||||
'href',
|
||||
'https://app.example/settings/appearance/?focus=message-link-preview'
|
||||
);
|
||||
expect(link).toHaveAttribute('data-settings-link-section', 'appearance');
|
||||
expect(link).toHaveAttribute('data-settings-link-focus', 'message-link-preview');
|
||||
expect(link).not.toHaveAttribute('data-mention-id');
|
||||
expect(link.className).toContain(customHtmlCss.Mention({}));
|
||||
expect(link.className).toContain(customHtmlCss.SettingsMention);
|
||||
});
|
||||
|
||||
it('renders matrix message permalinks with an icon instead of the Message prefix', () => {
|
||||
render(
|
||||
<div>
|
||||
{renderMatrixMention(
|
||||
{
|
||||
getUserId: () => '@alice:example.org',
|
||||
getRoom: () => ({ roomId: '!room:example.org', name: 'Lobby' }),
|
||||
} as never,
|
||||
undefined,
|
||||
'https://matrix.to/#/!room:example.org/$event123',
|
||||
makeMentionCustomProps(undefined)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
const link = screen.getByRole('link', { name: '#Lobby' });
|
||||
expect(link).toHaveAttribute('data-mention-id', '!room:example.org');
|
||||
expect(link).toHaveAttribute('data-mention-event-id', '$event123');
|
||||
expect(link.className).toContain(customHtmlCss.Mention({}));
|
||||
expect(link.className).toContain(customHtmlCss.SettingsMention);
|
||||
expect(link).not.toHaveTextContent('Message:');
|
||||
expect(link.querySelector('[aria-hidden="true"]')).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -36,6 +36,8 @@ import { findAndReplace } from '$utils/findAndReplace';
|
||||
import { onEnterOrSpace } from '$utils/keyboard';
|
||||
import { copyToClipboard } from '$utils/dom';
|
||||
import { useTimeoutToggle } from '$hooks/useTimeoutToggle';
|
||||
import { parseSettingsPermalink } from '$features/settings/settingsLink';
|
||||
import { settingsSections } from '$features/settings/routes';
|
||||
import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze';
|
||||
import {
|
||||
parseMatrixToRoom,
|
||||
@@ -138,21 +140,26 @@ export const renderMatrixMention = (
|
||||
const mentionRoom = mx.getRoom(
|
||||
isRoomAlias(roomIdOrAlias) ? getCanonicalAliasRoomId(mx, roomIdOrAlias) : roomIdOrAlias
|
||||
);
|
||||
const fallbackContent = mentionRoom ? `#${mentionRoom.name}` : roomIdOrAlias;
|
||||
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
{...customProps}
|
||||
className={css.Mention({
|
||||
highlight: currentRoomId === (mentionRoom?.roomId ?? roomIdOrAlias),
|
||||
})}
|
||||
className={classNames(
|
||||
css.Mention({
|
||||
highlight: currentRoomId === (mentionRoom?.roomId ?? roomIdOrAlias),
|
||||
}),
|
||||
css.SettingsMention
|
||||
)}
|
||||
data-mention-id={mentionRoom?.roomId ?? roomIdOrAlias}
|
||||
data-mention-event-id={eventId}
|
||||
data-mention-via={viaServers?.join(',')}
|
||||
>
|
||||
{customProps.children
|
||||
? customProps.children
|
||||
: `Message: ${mentionRoom ? `#${mentionRoom.name}` : roomIdOrAlias}`}
|
||||
<span aria-hidden="true" className={css.SettingsMentionIcon}>
|
||||
<Icon size="50" src={Icons.Message} />
|
||||
</span>
|
||||
{customProps.children ? customProps.children : fallbackContent}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -160,8 +167,80 @@ export const renderMatrixMention = (
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const settingsSectionLabel = Object.fromEntries(
|
||||
settingsSections.map((section) => [section.id, section.label])
|
||||
) as Record<(typeof settingsSections)[number]['id'], string>;
|
||||
|
||||
const humanizeSettingsPermalinkPart = (value: string): string =>
|
||||
value
|
||||
.split(/[^a-zA-Z0-9]+/)
|
||||
.filter(Boolean)
|
||||
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
||||
.join(' ');
|
||||
|
||||
const getSettingsPermalinkLabel = (
|
||||
section: keyof typeof settingsSectionLabel,
|
||||
focus?: string
|
||||
): string => {
|
||||
const sectionLabel = settingsSectionLabel[section];
|
||||
const focusLabel = focus ? humanizeSettingsPermalinkPart(focus) : undefined;
|
||||
|
||||
return focusLabel ? `${sectionLabel} / ${focusLabel}` : sectionLabel;
|
||||
};
|
||||
|
||||
const getSettingsPermalinkChildren = ({
|
||||
href,
|
||||
section,
|
||||
focus,
|
||||
content,
|
||||
fallbackChildren,
|
||||
}: {
|
||||
href: string;
|
||||
section: keyof typeof settingsSectionLabel;
|
||||
focus?: string;
|
||||
content?: string;
|
||||
fallbackChildren?: ReactNode;
|
||||
}): ReactNode => {
|
||||
if (!content || content === href || content === safeDecodeUrl(href)) {
|
||||
return getSettingsPermalinkLabel(section, focus);
|
||||
}
|
||||
|
||||
return fallbackChildren ?? content;
|
||||
};
|
||||
|
||||
const renderSettingsPermalink = ({
|
||||
href,
|
||||
section,
|
||||
focus,
|
||||
handleMentionClick,
|
||||
content,
|
||||
fallbackChildren,
|
||||
}: {
|
||||
href: string;
|
||||
section: keyof typeof settingsSectionLabel;
|
||||
focus?: string;
|
||||
handleMentionClick?: ReactEventHandler<HTMLElement>;
|
||||
content?: string;
|
||||
fallbackChildren?: ReactNode;
|
||||
}) => (
|
||||
<a
|
||||
href={href}
|
||||
{...makeMentionCustomProps(handleMentionClick, content)}
|
||||
className={classNames(css.Mention({}), css.SettingsMention)}
|
||||
data-settings-link-section={section}
|
||||
data-settings-link-focus={focus}
|
||||
>
|
||||
<span aria-hidden="true" className={css.SettingsMentionIcon}>
|
||||
<Icon size="50" src={Icons.Setting} />
|
||||
</span>
|
||||
{getSettingsPermalinkChildren({ href, section, focus, content, fallbackChildren })}
|
||||
</a>
|
||||
);
|
||||
|
||||
export const factoryRenderLinkifyWithMention = (
|
||||
mentionRender: (href: string) => JSX.Element | undefined
|
||||
settingsLinkBaseUrl: string,
|
||||
mentionRender: (href: string) => JSX.Element | undefined,
|
||||
handleMentionClick?: ReactEventHandler<HTMLElement>
|
||||
): OptFn<(ir: IntermediateRepresentation) => any> => {
|
||||
const renderLink: OptFn<(ir: IntermediateRepresentation) => any> = ({
|
||||
tagName,
|
||||
@@ -176,6 +255,21 @@ export const factoryRenderLinkifyWithMention = (
|
||||
if (mention) return mention;
|
||||
}
|
||||
|
||||
if (tagName === 'a' && decodedHref) {
|
||||
const settingsPermalink = parseSettingsPermalink(settingsLinkBaseUrl, decodedHref);
|
||||
if (settingsPermalink) {
|
||||
const { section, focus } = settingsPermalink;
|
||||
return renderSettingsPermalink({
|
||||
href: decodedHref,
|
||||
section,
|
||||
focus,
|
||||
handleMentionClick,
|
||||
content,
|
||||
fallbackChildren: content,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return <a {...attributes}>{content}</a>;
|
||||
};
|
||||
|
||||
@@ -344,6 +438,7 @@ export const getReactCustomHtmlParser = (
|
||||
mx: MatrixClient,
|
||||
roomId: string | undefined,
|
||||
params: {
|
||||
settingsLinkBaseUrl: string;
|
||||
linkifyOpts: LinkifyOpts;
|
||||
highlightRegex?: RegExp;
|
||||
handleSpoilerClick?: ReactEventHandler<HTMLElement>;
|
||||
@@ -489,23 +584,41 @@ export const getReactCustomHtmlParser = (
|
||||
if (name === 'a' && typeof props.href === 'string') {
|
||||
const encodedHref = props.href;
|
||||
const decodedHref = encodedHref && safeDecodeUrl(encodedHref);
|
||||
if (!decodedHref || !testMatrixTo(decodedHref)) {
|
||||
return undefined;
|
||||
}
|
||||
const renderedChildren = renderChildren();
|
||||
|
||||
const content = children.find((child) => !(child instanceof DOMText))
|
||||
? undefined
|
||||
: children.map((c) => (c instanceof DOMText ? c.data : '')).join();
|
||||
|
||||
const mention = renderMatrixMention(
|
||||
mx,
|
||||
roomId,
|
||||
safeDecodeUrl(props.href),
|
||||
makeMentionCustomProps(params.handleMentionClick, content),
|
||||
params.nicknames
|
||||
);
|
||||
if (decodedHref && testMatrixTo(decodedHref)) {
|
||||
const mention = renderMatrixMention(
|
||||
mx,
|
||||
roomId,
|
||||
decodedHref,
|
||||
makeMentionCustomProps(params.handleMentionClick, content),
|
||||
params.nicknames
|
||||
);
|
||||
|
||||
if (mention) return mention;
|
||||
if (mention) return mention;
|
||||
}
|
||||
|
||||
if (decodedHref) {
|
||||
const settingsPermalink = parseSettingsPermalink(
|
||||
params.settingsLinkBaseUrl,
|
||||
decodedHref
|
||||
);
|
||||
if (settingsPermalink) {
|
||||
const { section, focus } = settingsPermalink;
|
||||
return renderSettingsPermalink({
|
||||
href: decodedHref,
|
||||
section,
|
||||
focus,
|
||||
handleMentionClick: params.handleMentionClick,
|
||||
content,
|
||||
fallbackChildren: renderedChildren,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (name === 'span' && 'data-mx-spoiler' in props) {
|
||||
|
||||
@@ -69,6 +69,7 @@ export interface Settings {
|
||||
developerTools: boolean;
|
||||
enableMSC4268CMD: boolean;
|
||||
settingsSyncEnabled: boolean;
|
||||
settingsLinkBaseUrlOverride?: string;
|
||||
|
||||
// Cosmetics!
|
||||
jumboEmojiSize: JumboEmojiSize;
|
||||
@@ -162,6 +163,7 @@ const defaultSettings: Settings = {
|
||||
|
||||
developerTools: false,
|
||||
settingsSyncEnabled: false,
|
||||
settingsLinkBaseUrlOverride: undefined,
|
||||
|
||||
// Cosmetics!
|
||||
jumboEmojiSize: 'normal',
|
||||
|
||||
@@ -171,6 +171,18 @@ export const Mention = recipe({
|
||||
},
|
||||
});
|
||||
|
||||
export const SettingsMention = style({
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
gap: config.space.S100,
|
||||
padding: `0 ${config.space.S100}`,
|
||||
});
|
||||
|
||||
export const SettingsMentionIcon = style({
|
||||
display: 'inline-flex',
|
||||
flexShrink: 0,
|
||||
});
|
||||
|
||||
export const Command = recipe({
|
||||
base: [
|
||||
DefaultReset,
|
||||
|
||||
+27
-14
@@ -187,22 +187,35 @@ export const scrollToBottom = (scrollEl: HTMLElement, behavior?: 'auto' | 'insta
|
||||
});
|
||||
};
|
||||
|
||||
export const copyToClipboard = (text: string) => {
|
||||
export const copyToClipboard = async (text: string): Promise<boolean> => {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(text);
|
||||
} else {
|
||||
const host = document.body;
|
||||
const copyInput = document.createElement('input');
|
||||
copyInput.style.position = 'fixed';
|
||||
copyInput.style.opacity = '0';
|
||||
copyInput.value = text;
|
||||
host.append(copyInput);
|
||||
|
||||
copyInput.select();
|
||||
copyInput.setSelectionRange(0, 99999);
|
||||
document.execCommand('Copy');
|
||||
copyInput.remove();
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const host = document.body;
|
||||
const copyInput = document.createElement('input');
|
||||
copyInput.style.position = 'fixed';
|
||||
copyInput.style.opacity = '0';
|
||||
copyInput.value = text;
|
||||
host.append(copyInput);
|
||||
|
||||
copyInput.select();
|
||||
copyInput.setSelectionRange(0, 99999);
|
||||
|
||||
let copied = false;
|
||||
try {
|
||||
copied = document.execCommand('Copy');
|
||||
} catch {
|
||||
copied = false;
|
||||
}
|
||||
|
||||
copyInput.remove();
|
||||
return copied;
|
||||
};
|
||||
|
||||
export const setFavicon = (url: string): void => {
|
||||
|
||||
@@ -30,6 +30,7 @@ describe('NON_SYNCABLE_KEYS', () => {
|
||||
'isPeopleDrawer',
|
||||
'isWidgetDrawer',
|
||||
'memberSortFilterIndex',
|
||||
'settingsLinkBaseUrlOverride',
|
||||
'developerTools',
|
||||
'settingsSyncEnabled',
|
||||
] as const;
|
||||
|
||||
@@ -14,6 +14,7 @@ export const NON_SYNCABLE_KEYS = new Set<keyof Settings>([
|
||||
'isPeopleDrawer',
|
||||
'isWidgetDrawer',
|
||||
'memberSortFilterIndex',
|
||||
'settingsLinkBaseUrlOverride',
|
||||
// Developer / diagnostic
|
||||
'developerTools',
|
||||
// Sync toggle itself must never be uploaded (it's device-local)
|
||||
|
||||
Reference in new issue
Block a user