+ {acc.adapters.map((adp) => (
+
- {CONN_STATUS_LABEL[a.status]}
+ {CONN_STATUS_LABEL[adp.status]}
- {a.name}
- {ADAPTER_KIND_LABEL[a.kind]}
+ {adp.name}
+ {ADAPTER_KIND_LABEL[adp.kind]}
-
{a.detail}
+
{adp.detail}
))}
diff --git a/packages/webui/src/contexts/LayoutContext.tsx b/packages/webui/src/contexts/LayoutContext.tsx
new file mode 100644
index 00000000..e3d4fd7c
--- /dev/null
+++ b/packages/webui/src/contexts/LayoutContext.tsx
@@ -0,0 +1,148 @@
+import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
+import { useApi } from '@/lib/api';
+import type { UiLayout, UiLayoutItem } from '@/types';
+
+// Client-side layout customization (the "C" half). The server stores the
+// layout in config/ui.json; this context loads it (authed `GET /api/ui`),
+// hands it to the sidebar + overview, and persists edits via the section-merge
+// `POST /api/ui {layout}` (so it never clobbers appearance).
+//
+// Reconciliation against the *known* catalogue is the CONSUMER's job
+// (`reconcileLayoutItems`), so the context stays a dumb store and adding a new
+// block / nav item later doesn't need a context change — it just appears.
+
+const DEFAULT_OVERVIEW_BLOCKS: UiLayoutItem[] = [
+ { id: 'stats', visible: true },
+ { id: 'connections', visible: true },
+ { id: 'alerts', visible: true },
+ { id: 'host', visible: true },
+ { id: 'sessions', visible: true },
+];
+
+const DEFAULT_NAV_ITEMS: UiLayoutItem[] = [
+ { id: '/', visible: true },
+ { id: '/processes', visible: true },
+ { id: '/config', visible: true },
+ { id: '/logs', visible: true },
+ { id: '/settings', visible: true },
+];
+
+export const DEFAULT_LAYOUT: UiLayout = {
+ overviewBlocks: DEFAULT_OVERVIEW_BLOCKS.map((i) => ({ ...i })),
+ navItems: DEFAULT_NAV_ITEMS.map((i) => ({ ...i })),
+};
+
+/**
+ * Order + visibility for a known catalogue: keep stored items that still exist
+ * (in their stored order + visibility), then append any catalogue entries the
+ * stored layout predates (visible). `pinned` ids are forced visible.
+ */
+export function reconcileLayoutItems(
+ stored: UiLayoutItem[] | undefined,
+ known: readonly string[],
+ pinned: readonly string[] = [],
+): UiLayoutItem[] {
+ const knownSet = new Set(known);
+ const seen = new Set
();
+ const out: UiLayoutItem[] = [];
+ for (const item of stored ?? []) {
+ if (!item || !knownSet.has(item.id) || seen.has(item.id)) continue;
+ seen.add(item.id);
+ out.push({ id: item.id, visible: pinned.includes(item.id) ? true : item.visible !== false });
+ }
+ for (const id of known) {
+ if (!seen.has(id)) out.push({ id, visible: true });
+ }
+ return out;
+}
+
+interface LayoutContextValue {
+ overviewBlocks: UiLayoutItem[];
+ navItems: UiLayoutItem[];
+ /** Persist a new overview-block order/visibility. */
+ setOverviewBlocks: (items: UiLayoutItem[]) => void;
+ /** Persist a new nav order/visibility. */
+ setNavItems: (items: UiLayoutItem[]) => void;
+ /** Reset both to defaults. */
+ resetLayout: () => void;
+}
+
+const LayoutContext = createContext(null);
+
+export function LayoutProvider({ children }: { children: ReactNode }) {
+ const api = useApi();
+ const [layout, setLayout] = useState(DEFAULT_LAYOUT);
+ const layoutRef = useRef(layout);
+ // Set once the user edits, so the initial GET (which may resolve AFTER the
+ // first edit) never clobbers their change.
+ const dirtyRef = useRef(false);
+ const saveTimer = useRef | null>(null);
+
+ useEffect(() => { layoutRef.current = layout; }, [layout]);
+
+ useEffect(() => {
+ let cancelled = false;
+ (async () => {
+ try {
+ const config = await api.ui.get();
+ // Seed from the server only if the user hasn't already edited (the
+ // overview + editor are interactive immediately, before this resolves).
+ if (!cancelled && !dirtyRef.current && config?.layout) setLayout(config.layout);
+ } catch {
+ /* keep defaults — layout is non-critical */
+ }
+ })();
+ return () => { cancelled = true; };
+ }, [api]);
+
+ // On unmount (e.g. logout), flush a pending debounced save so a last-moment
+ // edit isn't lost; best-effort (a cleared token just 401s harmlessly).
+ useEffect(() => () => {
+ if (saveTimer.current) {
+ clearTimeout(saveTimer.current);
+ void api.ui.save({ layout: layoutRef.current }).catch(() => { /* best-effort */ });
+ }
+ }, [api]);
+
+ const persist = useCallback((next: UiLayout) => {
+ dirtyRef.current = true;
+ layoutRef.current = next;
+ setLayout(next);
+ if (saveTimer.current) clearTimeout(saveTimer.current);
+ saveTimer.current = setTimeout(() => {
+ saveTimer.current = null; // mark not-pending so the unmount flush can't double-fire
+ void api.ui.save({ layout: next }).catch(() => { /* best-effort */ });
+ }, 300);
+ }, [api]);
+
+ const setOverviewBlocks = useCallback((items: UiLayoutItem[]) => {
+ persist({ ...layoutRef.current, overviewBlocks: items });
+ }, [persist]);
+
+ const setNavItems = useCallback((items: UiLayoutItem[]) => {
+ persist({ ...layoutRef.current, navItems: items });
+ }, [persist]);
+
+ const resetLayout = useCallback(() => {
+ persist({
+ overviewBlocks: DEFAULT_OVERVIEW_BLOCKS.map((i) => ({ ...i })),
+ navItems: DEFAULT_NAV_ITEMS.map((i) => ({ ...i })),
+ });
+ }, [persist]);
+
+ const value = useMemo(() => ({
+ overviewBlocks: layout.overviewBlocks,
+ navItems: layout.navItems,
+ setOverviewBlocks,
+ setNavItems,
+ resetLayout,
+ }), [layout, setOverviewBlocks, setNavItems, resetLayout]);
+
+ return {children};
+}
+
+export function useLayout(): LayoutContextValue {
+ const ctx = useContext(LayoutContext);
+ if (!ctx) throw new Error('useLayout must be used within LayoutProvider');
+ return ctx;
+}
diff --git a/packages/webui/src/lib/api/types.ts b/packages/webui/src/lib/api/types.ts
index 4dbe710f..1973cc67 100644
--- a/packages/webui/src/lib/api/types.ts
+++ b/packages/webui/src/lib/api/types.ts
@@ -82,8 +82,9 @@ export interface ApiClient {
ui: {
/** Full config (appearance + layout). Bearer-gated. */
get(): Promise;
- /** Persist the full config; returns the normalized server view. */
- save(config: UiConfig): Promise;
+ /** Persist config. Section-level merge: a payload with only `appearance`
+ * or only `layout` keeps the other section. Returns the normalized view. */
+ save(config: Partial): Promise;
/** Cosmetic appearance subset, usable pre-auth (login page theming). */
getPublic(): Promise;
/** Upload a background image (PNG/JPEG/WebP, ≤5MB). Returns updated config. */
diff --git a/packages/webui/src/router/app-layout.tsx b/packages/webui/src/router/app-layout.tsx
index e015799f..8b6bf5b0 100644
--- a/packages/webui/src/router/app-layout.tsx
+++ b/packages/webui/src/router/app-layout.tsx
@@ -7,6 +7,7 @@ import { MainLayout } from '@/components/layout/main-layout';
import { ConfirmDialog } from '@/components/confirm-dialog';
import { Skeleton } from '@/components/ui/skeleton';
import { AppStateProvider } from '@/contexts/AppStateContext';
+import { LayoutProvider } from '@/contexts/LayoutContext';
import { useSession } from '@/contexts/SessionContext';
import type { AccountConnections, HookProcessInfo, QQInfo, SystemInfo, UpdateInfo } from '@/types';
@@ -125,15 +126,17 @@ export function AppLayout() {
onLogout: handleLogout,
}}
>
-
- {/* Routes use `lazyRouteComponent` (router/index.tsx) for
- code-splitting, which suspends until the chunk is fetched.
- The chrome (sidebar / top bar) stays mounted across this
- boundary so only the page surface flashes a skeleton. */}
- }>
-
-
-
+
+
+ {/* Routes use `lazyRouteComponent` (router/index.tsx) for
+ code-splitting, which suspends until the chunk is fetched.
+ The chrome (sidebar / top bar) stays mounted across this
+ boundary so only the page surface flashes a skeleton. */}
+ }>
+
+
+
+