feat(webui): deep-link settings tabs via ?tab= and jump update banner to 关于
The settings sub-tab now lives in the URL (typed `?tab=` search param on the /settings route, validated against the tab whitelist; default 外观 omits it). The active tab is derived from the URL and tab clicks navigate (replace), so tabs are shareable/back-button friendly. The sidebar "有新版本可用" banner now links to /settings?tab=about, landing directly on 关于 (where 软件更新 lives) instead of the default settings tab.
This commit is contained in:
3 files changed
+22
-4
No files matched your search
@@ -170,6 +170,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
|
|||||||
<div className={cn('px-2 pt-2', collapsed && 'px-0')}>
|
<div className={cn('px-2 pt-2', collapsed && 'px-0')}>
|
||||||
<Link
|
<Link
|
||||||
to="/settings"
|
to="/settings"
|
||||||
|
search={{ tab: 'about' }}
|
||||||
onClick={onItemClick}
|
onClick={onItemClick}
|
||||||
title={updateInfo.latest ? `有新版本 v${updateInfo.latest} · 点击查看` : '有可用更新'}
|
title={updateInfo.latest ? `有新版本 v${updateInfo.latest} · 点击查看` : '有可用更新'}
|
||||||
aria-label="有可用更新"
|
aria-label="有可用更新"
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ import { ConfirmDialog } from '@/components/confirm-dialog';
|
|||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import { useAppState } from '@/contexts/AppStateContext';
|
import { useAppState } from '@/contexts/AppStateContext';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
import { settingsRoute, type SettingsTab } from '@/router';
|
||||||
type SettingsTab = 'appearance' | 'data' | 'advanced' | 'account' | 'about';
|
|
||||||
|
|
||||||
const TABS: { key: SettingsTab; label: string; icon: typeof Sun }[] = [
|
const TABS: { key: SettingsTab; label: string; icon: typeof Sun }[] = [
|
||||||
{ key: 'appearance', label: '外观', icon: Palette },
|
{ key: 'appearance', label: '外观', icon: Palette },
|
||||||
@@ -48,7 +47,13 @@ const TABS: { key: SettingsTab; label: string; icon: typeof Sun }[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export function SettingsPage() {
|
export function SettingsPage() {
|
||||||
const [tab, setTab] = useState<SettingsTab>('appearance');
|
// Active tab lives in the URL (`?tab=`) so it's deep-linkable — e.g. the
|
||||||
|
// sidebar update banner jumps straight to 关于. Default tab omits the param.
|
||||||
|
const { tab: urlTab } = settingsRoute.useSearch();
|
||||||
|
const navigate = settingsRoute.useNavigate();
|
||||||
|
const tab: SettingsTab = urlTab ?? 'appearance';
|
||||||
|
const setTab = (t: SettingsTab) =>
|
||||||
|
void navigate({ to: '/settings', search: t === 'appearance' ? {} : { tab: t }, replace: true });
|
||||||
const active = TABS.find((t) => t.key === tab);
|
const active = TABS.find((t) => t.key === tab);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -64,9 +64,21 @@ const logsRoute = createRoute({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
const settingsRoute = createRoute({
|
/** Settings sub-tabs — also the contract for the `?tab=` deep link. */
|
||||||
|
export const SETTINGS_TABS = ['appearance', 'data', 'advanced', 'account', 'about'] as const;
|
||||||
|
export type SettingsTab = (typeof SETTINGS_TABS)[number];
|
||||||
|
|
||||||
|
export const settingsRoute = createRoute({
|
||||||
path: '/settings',
|
path: '/settings',
|
||||||
getParentRoute: () => appLayoutRoute,
|
getParentRoute: () => appLayoutRoute,
|
||||||
|
// `?tab=` deep-links a settings sub-tab (e.g. the sidebar update banner jumps
|
||||||
|
// straight to 关于). Unknown/missing → omitted (the page falls back to 外观).
|
||||||
|
validateSearch: (search: Record<string, unknown>): { tab?: SettingsTab } => {
|
||||||
|
const t = search.tab;
|
||||||
|
return typeof t === 'string' && (SETTINGS_TABS as readonly string[]).includes(t)
|
||||||
|
? { tab: t as SettingsTab }
|
||||||
|
: {};
|
||||||
|
},
|
||||||
component: lazyRouteComponent(
|
component: lazyRouteComponent(
|
||||||
() => import('@/components/pages/settings-page'),
|
() => import('@/components/pages/settings-page'),
|
||||||
'SettingsPage',
|
'SettingsPage',
|
||||||
|
|||||||
Reference in new issue
Block a user