refactor(webui): migrate routing to TanStack Router
The four-page switch lived as a string union (Page) plus an if/else
chain in AppInner, with TopBar reverse-importing Sidebar's NAV_ITEMS
to find the icon for the active tab. Adding a page touched four
places and there was no URL, no history, no deep-linking.
Move routing behind @tanstack/react-router with a layout route
(AppLayout) that owns the polling lists, processOps, selectedUin
and the unload-failed alert; child routes render through <Outlet/>
and read shared state from a new AppStateContext. AuthBoundary still
gates login / forced-password-change above the router. Sidebar uses
<Link> + useRouterState for active state; TopBar and MainLayout look
up the current path the same way.
Behaviour-preserving:
- LoginPage / ChangePasswordPage still mount above the router.
- AppLayout never unmounts during navigation, so selectedUin,
processOps state, the polling state and the unload-failed dialog
all survive page switches just like before.
- Logout calls history.replaceState('/') so the next login lands on
the overview page, matching pre-router behaviour.
- The sidebar-active-pill layoutId animation and the page-transition
AnimatePresence are preserved, keyed off pathname instead of the
removed `active` prop.
New URLs (/, /config, /logs, /settings) work on refresh because the
backend already had SPA fallback in core/src/webui/server.ts. Bundle
grows ~84KB (gzip +27KB) for the router runtime.
This commit is contained in:
13 files changed
+413
-209
No files matched your search
@@ -22,18 +22,9 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { cn, formatBytes, formatUptime } from '@/lib/utils';
|
||||
import type { HookProcessInfo, QQInfo, SystemInfo } from '@/types';
|
||||
import type { HookProcessOps } from '@/hooks/use-hook-process-ops';
|
||||
|
||||
interface OverviewPageProps {
|
||||
qqList: QQInfo[];
|
||||
status: string;
|
||||
processList: HookProcessInfo[];
|
||||
systemInfo: SystemInfo | null;
|
||||
onRefreshProcesses: () => void;
|
||||
onRefreshSystem: () => void;
|
||||
processOps: HookProcessOps;
|
||||
}
|
||||
import type { HookProcessInfo } from '@/types';
|
||||
import { useAppState } from '@/contexts/AppStateContext';
|
||||
import { useSession } from '@/contexts/SessionContext';
|
||||
|
||||
const processStatusLabel: Record<HookProcessInfo['status'], string> = {
|
||||
available: '可加载',
|
||||
@@ -91,15 +82,10 @@ function StatTile({
|
||||
);
|
||||
}
|
||||
|
||||
export function OverviewPage({
|
||||
qqList,
|
||||
status,
|
||||
processList,
|
||||
systemInfo,
|
||||
onRefreshProcesses,
|
||||
onRefreshSystem,
|
||||
processOps,
|
||||
}: OverviewPageProps) {
|
||||
export function OverviewPage() {
|
||||
const { qqList, processList, systemInfo, processOps, refreshProcesses, refreshSystem } =
|
||||
useAppState();
|
||||
const { status } = useSession();
|
||||
const { statusOf, banner: processActionStatus, load, unload, refresh } = processOps;
|
||||
const [confirm, setConfirm] = useState<
|
||||
| { kind: 'load' | 'unload'; pid: number; name: string }
|
||||
@@ -157,7 +143,7 @@ export function OverviewPage({
|
||||
: '正在采集主机信息…'}
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={onRefreshSystem}>
|
||||
<Button variant="outline" size="sm" onClick={refreshSystem}>
|
||||
<RefreshCw className="size-3.5" /> 刷新
|
||||
</Button>
|
||||
</CardHeader>
|
||||
@@ -260,7 +246,7 @@ export function OverviewPage({
|
||||
加载 SnowLuma 后会监听登录状态,登录后自动接入 OneBot 流程
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={onRefreshProcesses}>
|
||||
<Button variant="outline" size="sm" onClick={refreshProcesses}>
|
||||
<RefreshCw className="size-3.5" /> 刷新
|
||||
</Button>
|
||||
</CardHeader>
|
||||
|
||||
Reference in new issue
Block a user