Heftig rekatorering
This commit is contained in:
parent
3261e4c3bf
commit
1e32dd67c4
5 changed files with 13 additions and 12 deletions
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
interface Props extends ExerciseConfig {
|
||||
value: number;
|
||||
defaultValue: number;
|
||||
}
|
||||
|
||||
let {
|
||||
|
|
@ -16,7 +15,7 @@
|
|||
}: Props = $props();
|
||||
|
||||
// Destructure the remaining props for easier access
|
||||
const { icon, name, quickAddOptions, defaultValue, unit } = restProps;
|
||||
const { icon, name, quickAddOptions, unit } = restProps;
|
||||
|
||||
const label = unit ? `${icon} ${name} (${unit})` : `${icon} ${name}`;
|
||||
|
||||
|
|
@ -47,7 +46,6 @@
|
|||
{min}
|
||||
{max}
|
||||
{step}
|
||||
{defaultValue}
|
||||
required={true}
|
||||
class="flex-1 rounded-md border border-gray-300 px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -3,17 +3,18 @@
|
|||
import ExerciseField from './ExerciseField.svelte';
|
||||
import { getTodayDateString, exampleWorkout, type WorkoutData, exercises } from '$lib/workout';
|
||||
import { getTodaysWorkout, saveWorkout } from './workout.remote';
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
let todayDate = getTodayDateString();
|
||||
|
||||
// Form state
|
||||
let form: WorkoutData = {
|
||||
let form: WorkoutData = $state({
|
||||
pushups: 0,
|
||||
situps: 0,
|
||||
plankSeconds: 0,
|
||||
hangups: 0,
|
||||
runKm: 0
|
||||
};
|
||||
});
|
||||
|
||||
onMount(async () => {
|
||||
const result = await getTodaysWorkout();
|
||||
|
|
@ -36,7 +37,7 @@
|
|||
<form {...saveWorkout}>
|
||||
<!-- Exercise Fields -->
|
||||
{#each exercises as { config, key }}
|
||||
<ExerciseField {...config} bind:value={form[key]} defaultValue={form[key]} />
|
||||
<ExerciseField {...config} bind:value={form[key]} />
|
||||
{/each}
|
||||
|
||||
<!-- Action Buttons -->
|
||||
|
|
@ -57,6 +58,7 @@
|
|||
<!-- Message Display -->
|
||||
{#if saveWorkout.result?.success}
|
||||
<div
|
||||
transition:fade={{ duration: 300 }}
|
||||
class="mb-4 rounded-md border border-green-200 bg-green-100 p-3 text-sm font-medium text-green-800"
|
||||
role="alert"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ import { command, form, query } from '$app/server';
|
|||
import { db } from '$lib/db';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { WorkoutData } from '../lib/workout/types';
|
||||
import { exerciseConfigs, exercises } from '$lib/workout';
|
||||
|
||||
export const saveWorkout = form(async (data) => {
|
||||
let pushups = Number(data.get('pushups'));
|
||||
let situps = Number(data.get('situps'));
|
||||
let plankSeconds = Number(data.get('plankSeconds'));
|
||||
let hangups = Number(data.get('hangups'));
|
||||
let runKm = Number(data.get('runKm'));
|
||||
let pushups = Number(data.get(exerciseConfigs.pushups.name));
|
||||
let situps = Number(data.get(exerciseConfigs.situps.name));
|
||||
let plankSeconds = Number(data.get(exerciseConfigs.plankSeconds.name));
|
||||
let hangups = Number(data.get(exerciseConfigs.hangups.name));
|
||||
let runKm = Number(data.get(exerciseConfigs.runKm.name));
|
||||
|
||||
// Validate input data
|
||||
if (typeof pushups !== 'number' || isNaN(pushups) || pushups < 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue