- /login: setup/login/TOTP states driven by server error codes, fixed-height error slot - console layout: GET /auth/session gate, redirect to /login, account popover (change password, logout) - home: six dashboard sections with SSE-driven refresh, automation switch and read-only reconcile toggle - settings tabs: downloaders, media servers, library roots, path mappings, site credentials, API keys (one-time plaintext), Pi upstream, cache/organize/retention/budget, automation - engine: runs list (status/name filters, cursor paging, stats tiles), run detail (step timeline, json payloads, signals, cancel) - audit: filterable list with detail sheet - vite: allow repo root in server.fs so deno-installed deps under node_modules/.deno load in dev Co-Authored-By: Claude Opus 5.5 <[email protected]>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { type GlobalSettings, type GlobalSettingsUpdate, mergeSettings } from "@umt/contracts";
|
|
import { apiData } from "~/lib/api.ts";
|
|
import { qk } from "~/lib/query-keys.ts";
|
|
|
|
export function useSettings() {
|
|
return useQuery({
|
|
queryKey: qk.settings,
|
|
queryFn: ({ signal }) => apiData<GlobalSettings>("/settings", { signal }),
|
|
});
|
|
}
|
|
|
|
/** PATCH /settings,乐观更新(失败回滚) */
|
|
export function useUpdateSettings() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (patch: GlobalSettingsUpdate) => apiData<GlobalSettings>("/settings", { method: "PATCH", body: patch }),
|
|
onMutate: async (patch) => {
|
|
await qc.cancelQueries({ queryKey: qk.settings });
|
|
const prev = qc.getQueryData<GlobalSettings>(qk.settings);
|
|
if (prev) qc.setQueryData(qk.settings, mergeSettings(prev, patch));
|
|
return { prev };
|
|
},
|
|
onError: (_e, _p, ctx) => {
|
|
if (ctx?.prev) qc.setQueryData(qk.settings, ctx.prev);
|
|
},
|
|
onSuccess: (data) => {
|
|
qc.setQueryData(qk.settings, data);
|
|
qc.invalidateQueries({ queryKey: qk.dashboard });
|
|
},
|
|
});
|
|
}
|