This commit is contained in:
Timothy Jaeryang Baek committed 2026-12-03 00:18:38 +04:00
1 parent ad202d7f4c
commit 6a9a048e12
7 files changed
+141 -9

No files matched your search

+1
View File
@@ -36,6 +36,7 @@ declare global {
inbox?: boolean;
inboxUserId?: string;
tab?: string;
settings?: boolean;
}
// interface Error {}
// interface Locals {}
@@ -669,8 +669,8 @@
}
if (isPresetModel(model)) {
showSettings.set(false);
await goto(`/workspace/models/edit?id=${encodeURIComponent(model.id)}`);
showSettings.set(false);
return;
}
@@ -685,8 +685,8 @@
id: `${model.id}-clone`,
name: `${model.name} (Clone)`
});
showSettings.set(false);
await goto('/workspace/models/create');
showSettings.set(false);
};
const exportModelHandler = async (model) => {
@@ -379,10 +379,10 @@
class="block truncate text-base-800 hover:text-base-1000 dark:text-base-200 dark:hover:text-base-0"
href={`/c/${chat.id}`}
title={chat?.title}
on:click={(event) => {
on:click={async (event) => {
event.preventDefault();
await goto(`/c/${chat.id}`);
showSettings.set(false);
goto(`/c/${chat.id}`);
}}
>
{chat?.title}
@@ -34,6 +34,8 @@
const i18n: Writable<any> = getContext('i18n');
export let show: boolean | string | SettingsModalRequest = false;
// Called with the open tab whenever it changes, so the page address can follow it.
export let onTabChange: (tab: string) => void = () => {};
let modalShow = false;
let lastShow: boolean | string | SettingsModalRequest = false;
let tabState: Record<string, unknown> | null = null;
@@ -628,6 +630,7 @@
$: if (modalShow && selectedTab) {
scrollToSelectedTab();
onTabChange(selectedTab);
}
$: if ($config && $user) {
+59
View File
@@ -0,0 +1,59 @@
// Readable addresses for the settings tabs: /settings/<slug> and /settings/admin/<slug>.
const SETTINGS_SLUGS: Record<string, string> = {
general: 'preferences',
shortcuts: 'keyboard',
audio: 'audio',
account: 'profile',
personalization: 'personalization',
notifications: 'notifications',
archived_chats: 'archived-chats',
data_controls: 'data-controls',
usage: 'usage',
about: 'about',
'admin:general': 'admin/general',
'admin:authentication': 'admin/authentication',
'admin:features': 'admin/features',
'admin:tasks': 'admin/tasks',
'admin:interface': 'admin/interface',
'admin:analytics': 'admin/analytics',
'admin:db': 'admin/database',
'admin:connections': 'admin/connections',
'admin:models': 'admin/models',
'admin:subagents': 'admin/sub-agents',
'admin:integrations': 'admin/integrations',
'admin:web': 'admin/web-search',
'admin:documents': 'admin/documents',
'admin:images': 'admin/images',
'admin:audio': 'admin/audio',
'admin:code-execution': 'admin/code-execution',
'admin:pipelines': 'admin/pipelines'
};
// Older admin addresses that point at tabs that were merged or renamed.
const SETTINGS_ALIASES: Record<string, string> = {
'admin/apps': 'admin:integrations',
'admin/videos': 'admin:images',
'admin/db': 'admin:db',
'admin/web': 'admin:web',
'admin/subagents': 'admin:subagents'
};
export const settingsPath = (tab: string) =>
`/settings/${SETTINGS_SLUGS[tab] ?? SETTINGS_SLUGS.general}`;
/** The tab (and model, for /settings/admin/models/<id>) a settings address points at. */
export const parseSettingsPath = (pathname: string): { tab: string; modelId?: string } | null => {
const match = pathname.match(/^\/settings(?:\/(.*?))?\/?$/);
if (!match) return null;
const rest = match[1] ?? '';
if (!rest) return { tab: 'general' };
const model = rest.match(/^admin\/models\/(.+)$/);
if (model) return { tab: 'admin:models', modelId: decodeURIComponent(model[1]) };
const tab =
Object.keys(SETTINGS_SLUGS).find((id) => SETTINGS_SLUGS[id] === rest) ??
SETTINGS_ALIASES[rest] ??
Object.keys(SETTINGS_SLUGS).find((id) => id === rest || id === rest.replace('/', ':'));
return { tab: tab ?? 'general' };
};
+59 -5
View File
@@ -3,7 +3,7 @@
import { onMount, tick, getContext, setContext } from 'svelte';
import type { AppLayoutContext } from '$lib/types';
import { goto } from '$app/navigation';
import { afterNavigate, beforeNavigate, goto, pushState, replaceState } from '$app/navigation';
import { page } from '$app/stores';
import { fade } from 'svelte/transition';
@@ -60,6 +60,7 @@
import Spinner from '$lib/components/common/Spinner.svelte';
import { loadKeybindings, matchKeybinding, Shortcut } from '$lib/shortcuts';
import { canUseTemporaryChats } from '$lib/utils/settings-access';
import { parseSettingsPath, settingsPath } from '$lib/utils/settings-routes';
const i18n = getContext('i18n');
const getUserSettings = getContext<(token: string) => Promise<any>>('getUserSettings');
@@ -203,22 +204,75 @@
}
handledSettingsUrl = urlKey;
showSettings.set(
const tab =
requestedSettings.startsWith('admin:') && $user?.role !== 'admin'
? 'general'
: requestedSettings
);
: requestedSettings;
const modelId = $page.url.searchParams.get('model');
// Strip the params before opening: opening adds the settings address to history, and
// this replace would otherwise overwrite it.
const params = new URLSearchParams($page.url.searchParams);
params.delete('settings');
params.delete('model');
const query = params.toString();
await goto(`${$page.url.pathname}${query ? `?${query}` : ''}${$page.url.hash}`, {
replaceState: true,
noScroll: true,
keepFocus: true
});
showSettings.set(tab === 'admin:models' && modelId ? { tab, state: { id: modelId } } : tab);
};
// Settings has its own address. Opening it adds one history entry, switching tabs replaces
// it, and closing steps back off it, so Back closes settings in one step.
let settingsEntry = false;
let settingsOpen = false;
let stepBackPending = false;
let leavingSettings = false;
const syncSettingsUrl = (tab: string) => {
const path = settingsPath(tab);
if (settingsEntry) {
if (location.pathname !== path) replaceState(path, { ...$page.state, settings: true });
} else {
pushState(path, { ...$page.state, settings: true });
}
};
$: onSettingsEntry(!!$page.state.settings);
const onSettingsEntry = (entry: boolean) => {
if (entry === settingsEntry) return;
settingsEntry = entry;
if (!entry) {
// Left the settings entry: Back, or the step back taken when settings closed.
if (stepBackPending) stepBackPending = false;
else if ($showSettings) showSettings.set(false);
} else if (!$showSettings) {
// Forward (or Back) onto a settings entry reopens it on that tab.
showSettings.set(parseSettingsPath(location.pathname)?.tab ?? 'general');
}
};
$: onSettingsOpen(!!$showSettings);
const onSettingsOpen = (open: boolean) => {
if (open === settingsOpen) return;
settingsOpen = open;
if (!open && settingsEntry && !leavingSettings) {
stepBackPending = true;
history.back();
}
};
// Following a link out of settings keeps the settings entry behind it in history.
beforeNavigate((navigation) => {
if (navigation.type !== 'popstate' && settingsEntry) leavingSettings = true;
});
afterNavigate(() => {
leavingSettings = false;
});
const gotoAuth = async () => {
const currentUrl = `${$page.url.pathname}${$page.url.search}`;
await goto(`/auth?redirect=${encodeURIComponent(currentUrl)}`);
@@ -468,7 +522,7 @@
</script>
{#if settingsRequested}
<SettingsModal bind:show={$showSettings} />
<SettingsModal bind:show={$showSettings} onTabChange={syncSettingsUrl} />
{/if}
<ChangelogModal bind:show={$showChangelog} />
<UserProfileModal bind:userId={profileUserId} />
@@ -0,0 +1,15 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import { parseSettingsPath } from '$lib/utils/settings-routes';
// Opened directly (link, bookmark or refresh): load the app with settings open on this tab.
onMount(() => {
const request = parseSettingsPath($page.url.pathname) ?? { tab: 'general' };
const params = new URLSearchParams($page.url.searchParams);
params.set('settings', request.tab);
if (request.modelId) params.set('model', request.modelId);
goto(`/?${params.toString()}`, { replaceState: true });
});
</script>