diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index 67b41d6..067a90c 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -40,15 +40,6 @@ let configError = $state(null); let configSuccess = $state(null); - async function loadConfig() { - const res = await fetch(`${api}/config`); - if (!res.ok) return; - const c = await res.json(); - configYoloLabel = c.yoloLabel ?? 'YOLO mode'; - configYoloDescription = c.yoloDescription ?? '(cross-group conversions)'; - configYoloVisibility = c.yoloVisibility ?? 'auto'; - } - async function saveConfig() { configSaving = true; configError = null; @@ -227,16 +218,39 @@ } // ── Load data ──────────────────────────────────────────────────────────────── + let loadDataInFlight = false; async function loadData() { - const [res, gres] = await Promise.all([ - fetch(`${api}/units`), - fetch(`${api}/groups`) - ]); - if (!res.ok) return; - const units: Unit[] = await res.json(); - const groups: Group[] = gres.ok ? await gres.json() : []; - unitsData = { units, groups }; - expandedGroups = new Set([...expandedGroups, ...groups.map((g) => g.id)]); + if (loadDataInFlight) return; + loadDataInFlight = true; + try { + const [res, gres] = await Promise.all([ + fetch(`${api}/units`), + fetch(`${api}/groups`) + ]); + if (!res.ok) return; + const units: Unit[] = await res.json(); + const groups: Group[] = gres.ok ? await gres.json() : []; + unitsData = { units, groups }; + expandedGroups = new Set([...expandedGroups, ...groups.map((g) => g.id)]); + } finally { + loadDataInFlight = false; + } + } + + let loadConfigInFlight = false; + async function loadConfig() { + if (loadConfigInFlight) return; + loadConfigInFlight = true; + try { + const res = await fetch(`${api}/config`); + if (!res.ok) return; + const c = await res.json(); + configYoloLabel = c.yoloLabel ?? 'YOLO mode'; + configYoloDescription = c.yoloDescription ?? '(cross-group conversions)'; + configYoloVisibility = c.yoloVisibility ?? 'auto'; + } finally { + loadConfigInFlight = false; + } } onMount(() => { loadData(); loadConfig(); });