milestone 9: react spa admin ui, frontend ci and embedded dist

This commit is contained in:
2026-08-02 13:04:09 +02:00
parent 5253c47303
commit 617cc966a2
82 changed files with 11833 additions and 17 deletions
+42
View File
@@ -0,0 +1,42 @@
import { MutationCache, QueryCache, QueryClient } from "@tanstack/react-query";
import { ApiError } from "@/lib/api";
import { rememberAuthRequired } from "@/auth/store";
export function handleUnauthorized(error: unknown): void {
if (!(error instanceof ApiError) || error.status !== 401) return;
if (window.location.pathname === "/login") return;
rememberAuthRequired(true);
const current = window.location.pathname + window.location.search;
window.location.assign(`/login?redirect=${encodeURIComponent(current)}`);
}
function shouldRetry(failureCount: number, error: unknown): boolean {
if (error instanceof ApiError && error.status >= 400 && error.status < 500 && error.status !== 429) {
return false;
}
return failureCount < 2;
}
function retryDelay(attemptIndex: number, error: unknown): number {
if (error instanceof ApiError && error.status === 429 && error.retryAfter !== undefined) {
return error.retryAfter * 1000;
}
return Math.min(1000 * 2 ** attemptIndex, 30_000);
}
export function createQueryClient(): QueryClient {
return new QueryClient({
queryCache: new QueryCache({ onError: handleUnauthorized }),
mutationCache: new MutationCache({ onError: handleUnauthorized }),
defaultOptions: {
queries: {
staleTime: 30_000,
retry: shouldRetry,
retryDelay,
},
mutations: {
retry: false,
},
},
});
}