Files
SnowLuma/packages/webui/src/router/index.tsx
T
DrSmoothl 71be3ae2e1 feat(webui): split overview into a processes page + mobile/ultrawide pass
The homepage was doing double duty — monitoring + injection control. Split it:

- New /processes page ("进程注入", sidebar #2) owns the QQ-process control
  surface (load / unload / refresh / probe-login + its dialogs). Overview is
  now a read-only dashboard: stats, host metrics, online accounts, plus a
  read-only injection-summary tile (online / loadable, links to /processes)
  and a first-run CTA that points at /processes while nothing is online.
  Route + AppPath + nav item wired; state/polling stay layout-owned.

Responsive + a11y pass:
- Mobile sidebar Sheet gets an sr-only title + description, fixing the Radix
  "DialogContent requires a DialogTitle" accessibility error.
- Log rows stack on phones (meta line + full-width message) instead of a
  ~40px column that broke every few chars; time parses defensively so a
  non-ISO value never renders "Invalid Date".
- Process cards stack on phones (info row + actions row) so name / PID / path
  stop collapsing to "Q.."; the status badge no longer wraps.
- Config tab strip scrolls horizontally on phones instead of wrapping to
  three rows; account strip defaults collapsed ≤lg; header buttons wrap.
- Dialogs keep a 1rem gutter on tiny screens via w-[calc(100vw-2rem)].
- Content widens to 1600px on ≥2xl; account/process grids gain a column at
  2xl so >1700px screens aren't mostly empty gutter.
2026-05-30 16:56:34 +08:00

95 lines
2.7 KiB
TypeScript

import {
createRootRoute,
createRoute,
createRouter,
lazyRouteComponent,
Outlet,
} from '@tanstack/react-router';
import { AppLayout } from './app-layout';
// Imported eagerly (not lazy): the error / not-found fallbacks must render
// even when a route's own chunk failed to load.
import { ErrorPage, NotFoundPage } from '@/components/pages/status-screens';
// Page components are loaded on demand so the initial paint only ships
// the auth surface + layout shell. With `defaultPreload: 'intent'` set
// below, the router warms the next chunk on hover/focus, so navigation
// still feels instant after the first idle moment. Previously every
// page (overview / config / logs / settings) lived in the single
// ~600 kB bundle that Vite explicitly warned about — config-page edit
// dialog alone pulls in a large form surface that most users never
// touch on first visit.
const rootRoute = createRootRoute({
component: () => <Outlet />,
});
const appLayoutRoute = createRoute({
id: 'app-layout',
getParentRoute: () => rootRoute,
component: AppLayout,
});
const overviewRoute = createRoute({
path: '/',
getParentRoute: () => appLayoutRoute,
component: lazyRouteComponent(
() => import('@/components/pages/overview-page'),
'OverviewPage',
),
});
const processesRoute = createRoute({
path: '/processes',
getParentRoute: () => appLayoutRoute,
component: lazyRouteComponent(
() => import('@/components/pages/processes-page'),
'ProcessesPage',
),
});
const configRoute = createRoute({
path: '/config',
getParentRoute: () => appLayoutRoute,
component: lazyRouteComponent(
() => import('@/components/pages/config-page'),
'ConfigPage',
),
});
const logsRoute = createRoute({
path: '/logs',
getParentRoute: () => appLayoutRoute,
component: lazyRouteComponent(
() => import('@/components/pages/logs-page'),
'LogsPage',
),
});
const settingsRoute = createRoute({
path: '/settings',
getParentRoute: () => appLayoutRoute,
component: lazyRouteComponent(
() => import('@/components/pages/settings-page'),
'SettingsPage',
),
});
const routeTree = rootRoute.addChildren([
appLayoutRoute.addChildren([overviewRoute, processesRoute, configRoute, logsRoute, settingsRoute]),
]);
export const appRouter = createRouter({
routeTree,
defaultPreload: 'intent',
defaultNotFoundComponent: () => <NotFoundPage />,
defaultErrorComponent: ({ error, reset }) => <ErrorPage error={error} reset={reset} />,
});
declare module '@tanstack/react-router' {
interface Register {
router: typeof appRouter;
}
}
/** Paths registered on the layout — single source of truth for nav metadata. */
export type AppPath = '/' | '/processes' | '/config' | '/logs' | '/settings';