edit athlete data
This commit is contained in:
@@ -2,11 +2,15 @@
|
||||
import { onMount } from 'svelte';
|
||||
import type { AthleteJson, BASIndex, ActivitySummary } from '../lib/types';
|
||||
import MmpChart from './MmpChart.svelte';
|
||||
import AthleteDrawer from './AthleteDrawer.svelte';
|
||||
|
||||
let athlete: AthleteJson | null = null;
|
||||
let activities: ActivitySummary[] = [];
|
||||
let loading = true;
|
||||
let error: string | null = null;
|
||||
let drawerOpen = false;
|
||||
|
||||
const editUrl = import.meta.env.PUBLIC_EDIT_URL ?? '';
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
@@ -19,6 +23,7 @@
|
||||
const index: BASIndex = await indexRes.json();
|
||||
// Only activities with power data contribute to the curve
|
||||
activities = index.activities.filter(a => a.mmp && a.privacy !== 'private');
|
||||
|
||||
} catch (e: any) {
|
||||
error = e.message;
|
||||
} finally {
|
||||
@@ -26,6 +31,13 @@
|
||||
}
|
||||
});
|
||||
|
||||
async function onSaved() {
|
||||
// Reload athlete.json after edits are saved
|
||||
const res = await fetch(`${import.meta.env.BASE_URL}data/athlete.json?t=${Date.now()}`);
|
||||
if (res.ok) athlete = await res.json();
|
||||
drawerOpen = false;
|
||||
}
|
||||
|
||||
function fmtZone(zones: [number, number][], i: number): string {
|
||||
const [lo, hi] = zones[i];
|
||||
return hi >= 9000 ? `${lo}+ W` : `${lo}–${hi} W`;
|
||||
@@ -42,6 +54,16 @@
|
||||
<p class="text-red-400 text-sm">{error}</p>
|
||||
{:else if athlete}
|
||||
|
||||
<!-- Edit button (only when edit server is configured) -->
|
||||
{#if editUrl}
|
||||
<div class="flex justify-end mb-6">
|
||||
<button
|
||||
on:click={() => drawerOpen = true}
|
||||
class="px-4 py-2 text-sm border border-zinc-700 hover:border-zinc-500 text-zinc-300 hover:text-white rounded-md transition-colors"
|
||||
>Edit profile</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Power curve section -->
|
||||
<section class="mb-10">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Power Curve</h2>
|
||||
@@ -109,3 +131,11 @@
|
||||
</section>
|
||||
|
||||
{/if}
|
||||
|
||||
{#if drawerOpen && editUrl}
|
||||
<AthleteDrawer
|
||||
{editUrl}
|
||||
on:close={() => drawerOpen = false}
|
||||
on:saved={onSaved}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user