fix: athlete page falls back to /api/athlete when static file not yet rebuilt

This commit is contained in:
Davide Scaini
2026-04-10 15:43:01 +02:00
parent 6a8ef984cb
commit f8e02f3da2
+14 -3
View File
@@ -42,7 +42,15 @@
loadAthlete(import.meta.env.BASE_URL, athleteUrl || undefined),
loadIndex(import.meta.env.BASE_URL, indexUrl || undefined),
]);
athlete = athleteData as AthleteJson | null;
// Static file may not exist yet if the background rebuild hasn't finished — fall back to API
let resolvedAthlete = athleteData as AthleteJson | null;
if (!resolvedAthlete && editEnabled) {
try {
const r = await fetch('/api/athlete', { credentials: 'include' });
if (r.ok) resolvedAthlete = await r.json() as AthleteJson;
} catch { /* ignore */ }
}
athlete = resolvedAthlete;
activities = index.activities.filter(a => a.mmp && a.privacy !== 'private');
} catch (e: any) {
error = e.message;
@@ -52,8 +60,11 @@
});
async function onSaved() {
const res = await fetch(`${import.meta.env.BASE_URL}data/athlete.json?t=${Date.now()}`);
if (res.ok) athlete = await res.json();
// Try static file first; fall back to API (works before the background rebuild finishes)
const staticUrl = athleteUrl || `${import.meta.env.BASE_URL}data/athlete.json`;
let res = await fetch(`${staticUrl}?t=${Date.now()}`);
if (!res.ok) res = await fetch('/api/athlete', { credentials: 'include' });
if (res.ok) athlete = await res.json() as AthleteJson;
drawerOpen = false;
}