Skip to content

Commit

Permalink
fix: load workout note when editing workouts
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Jan 23, 2025
1 parent 9711f04 commit f40305d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/lib/trpc/routes/workouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type TodaysWorkoutData = {
cycleNumber: number;
splitDayName: string;
};
note: string | null;
};

type WorkoutExercisesWithPreviousData = {
Expand Down Expand Up @@ -258,7 +259,8 @@ export const workouts = t.router({
workoutExercises: [],
userBodyweight,
startedAt: new Date(),
endedAt: null
endedAt: null,
note: null
};

if (data === null) {
Expand Down Expand Up @@ -319,7 +321,8 @@ export const workouts = t.router({
workoutExercises: [],
userBodyweight,
startedAt: new Date(),
endedAt: null
endedAt: null,
note: null
};

if (data === null) {
Expand Down
5 changes: 2 additions & 3 deletions src/routes/workouts/manage/overview/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
let savingWorkout = $state(false);
let workoutExercises = $derived(workoutRunes.workoutExercises ?? []);
let workoutNote = $state<string>();
function preProcessSetData() {
if (workoutRunes.workoutData === null || workoutRunes.workoutExercises === null) return;
Expand All @@ -39,7 +38,7 @@
const userBodyweight = workoutRunes.workoutData.userBodyweight;
const createData: RouterInputs['workouts']['create'] = {
workoutData: { ...workoutRunes.workoutData, userBodyweight, note: workoutNote },
workoutData: { ...workoutRunes.workoutData, userBodyweight, note: workoutRunes.workoutData.note ?? undefined },
workoutExercises: workoutRunes.workoutExercises.map((ex, idx) => {
const { sets, ...exercise } = ex;
return { ...exercise, exerciseIndex: idx };
Expand Down Expand Up @@ -157,7 +156,7 @@

<div class="mt-4 flex w-full flex-col gap-1.5">
<Label for="workout-note">Workout note</Label>
<Textarea id="workout-note" placeholder="Type here (optional)" bind:value={workoutNote}></Textarea>
<Textarea id="workout-note" placeholder="Type here (optional)" bind:value={workoutRunes.workoutData!.note}></Textarea>
</div>

<div class="mt-auto grid grid-cols-2 gap-1">
Expand Down
3 changes: 2 additions & 1 deletion src/routes/workouts/manage/workoutRunes.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ function createWorkoutRunes() {
startedAt: workout.startedAt,
endedAt: workout.endedAt,
userBodyweight: workout.userBodyweight,
workoutExercises: []
workoutExercises: [],
note: workout.note
};
workoutExercises = workout.workoutExercises.map((ex) => {
const { id, workoutId, ...exercise } = ex;
Expand Down
6 changes: 6 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"paths": {
"$lib": ["../src/lib"],
"$lib/*": ["../src/lib/*"]
}
}

0 comments on commit f40305d

Please sign in to comment.