fix: athlete page falls back to /api/athlete when static file not yet rebuilt
This commit is contained in:
@@ -42,7 +42,15 @@
|
|||||||
loadAthlete(import.meta.env.BASE_URL, athleteUrl || undefined),
|
loadAthlete(import.meta.env.BASE_URL, athleteUrl || undefined),
|
||||||
loadIndex(import.meta.env.BASE_URL, indexUrl || 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');
|
activities = index.activities.filter(a => a.mmp && a.privacy !== 'private');
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
error = e.message;
|
error = e.message;
|
||||||
@@ -52,8 +60,11 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function onSaved() {
|
async function onSaved() {
|
||||||
const res = await fetch(`${import.meta.env.BASE_URL}data/athlete.json?t=${Date.now()}`);
|
// Try static file first; fall back to API (works before the background rebuild finishes)
|
||||||
if (res.ok) athlete = await res.json();
|
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;
|
drawerOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user