diff --git a/apps/portal/src/lib/components/PlayersTable.svelte b/apps/portal/src/lib/components/PlayersTable.svelte index 911e641..099e60c 100644 --- a/apps/portal/src/lib/components/PlayersTable.svelte +++ b/apps/portal/src/lib/components/PlayersTable.svelte @@ -29,6 +29,8 @@ activityPerformances: ActivityPerformance[]; /** JSON snapshot of {player, activityPerformances} as of the last successful save/load. "" means never saved. */ savedSnapshot: string; + /** whether the metrics/performance editing panel is open — collapsed by default, since levels are the primary thing being compared */ + expanded?: boolean; saving?: boolean; saveError?: string; deleting?: boolean; @@ -59,6 +61,9 @@ const levelCalculator = $derived(new LevelCalculator(allStandards)); + // toggle + name + overall + one column per attribute + actions + const TABLE_COLUMNS = 4 + Object.keys(Attribute).length; + let calculations = $state([]); let loading = $state(true); let loadError = $state(null); @@ -121,12 +126,22 @@ calculation.saving = true; calculation.saveError = undefined; try { - const res = await api.assessments.me.post({ - player: calculation.player, - activityPerformances: calculation.activityPerformances, - }); - if (res.error) throw res.error; - calculation.id = res.data?.id; + if (calculation.id) { + const res = await api + .assessments({ id: calculation.id }) + .put({ + player: calculation.player, + activityPerformances: calculation.activityPerformances, + }); + if (res.error) throw res.error; + } else { + const res = await api.assessments.me.post({ + player: calculation.player, + activityPerformances: calculation.activityPerformances, + }); + if (res.error) throw res.error; + calculation.id = res.data?.id; + } calculation.savedSnapshot = snapshotOf( calculation.player, calculation.activityPerformances, @@ -190,6 +205,7 @@ return { key: crypto.randomUUID(), savedSnapshot: "", // never saved — always dirty until the first save + expanded: true, // a brand new player needs its details filled in right away player: { name: name, metrics: { @@ -223,7 +239,7 @@ const formatSeconds = (ms: number) => (ms / 1000).toFixed(2) + " seconds"; const performanceOptionsFromActivity = function (activity: Activity) { - const options: { name: string; value: string }[] = []; + const options: { name: string; value: number }[] = []; switch (activity) { case Activity.BackSquat: case Activity.Deadlift: @@ -231,7 +247,7 @@ for (let i = 0; i < 600; ++i) { options.push({ name: String(i) + " lb", - value: String(lbToKg(i)), + value: lbToKg(i), }); } break; @@ -239,7 +255,7 @@ case Activity.Run: { const MAX_MIN = 30; for (let ms = 0; ms <= MAX_MIN * 60_000; ms += 1_000) { - options.push({ name: formatMs(ms), value: String(ms) }); + options.push({ name: formatMs(ms), value: ms }); } break; } @@ -250,7 +266,7 @@ const inches = halfStep / 2; options.push({ name: inchesToFeetInches(inches), - value: (inches * 2.54).toFixed(1), + value: Number((inches * 2.54).toFixed(1)), }); } break; @@ -262,7 +278,7 @@ for (let ms = MIN_MS; ms <= MAX_MS; ms += 10) { options.push({ name: formatSeconds(ms), - value: String(ms), + value: ms, }); } break; @@ -298,163 +314,241 @@ {/if} -
- {#each calculations as calculation, index (calculation.key)} -
-
-
- - {#if isDirty(calculation)} -
- Unsaved -
- {/if} -
- -
    -
  • -
    -
    OVERALL
    -
    - {calculation?.levels?.player || "N/A"} -
    -
    -
  • - - {#each Object.values(Attribute) as attribute (attribute)} -
  • -
    -
    - {attribute} -
    -
    - {calculation?.levels?.attributes?.[ - attribute - ] || "N/A"} -
    -
    -
  • - {/each} -
- -
- (calculation.levels = levelCalculator.calculate( - calculation.player, - calculation.activityPerformances, - ))} - > -
- - -