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')}>
|
||||
<Link
|
||||
to="/settings"
|
||||
search={{ tab: 'about' }}
|
||||
onClick={onItemClick}
|
||||
title={updateInfo.latest ? `有新版本 v${updateInfo.latest} · 点击查看` : '有可用更新'}
|
||||
aria-label="有可用更新"
|
||||
|
||||
@@ -36,8 +36,7 @@ import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { useAppState } from '@/contexts/AppStateContext';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
type SettingsTab = 'appearance' | 'data' | 'advanced' | 'account' | 'about';
|
||||
import { settingsRoute, type SettingsTab } from '@/router';
|
||||
|
||||
const TABS: { key: SettingsTab; label: string; icon: typeof Sun }[] = [
|
||||
{ key: 'appearance', label: '外观', icon: Palette },
|
||||
@@ -48,7 +47,13 @@ const TABS: { key: SettingsTab; label: string; icon: typeof Sun }[] = [
|
||||
];
|
||||
|
||||
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);
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user