From 67bb9151ad8d0fb669ed73f5d933f6e576922a7a Mon Sep 17 00:00:00 2001 From: Christian Carlsson Date: Wed, 18 Dec 2024 16:00:09 +0000 Subject: [PATCH] refact: web: workout session (#248) --- server/repo/repo.go | 13 +- server/testing/factory/factory_workout.go | 6 + web/src/ui/components/AppButton.vue | 6 +- web/src/ui/components/AppList.vue | 16 +- web/src/ui/workouts/EditWorkout.vue | 26 +- web/src/ui/workouts/StartWorkout.vue | 289 +++++++++++++--------- web/src/utils/numbers.ts | 3 + 7 files changed, 216 insertions(+), 143 deletions(-) create mode 100644 web/src/utils/numbers.ts diff --git a/server/repo/repo.go b/server/repo/repo.go index e3c9c725..50208e8c 100644 --- a/server/repo/repo.go +++ b/server/repo/repo.go @@ -840,12 +840,15 @@ func (r *repo) DeleteWorkout(ctx context.Context, opts ...DeleteWorkoutOpt) erro func (r *repo) GetPreviousWorkoutSets(ctx context.Context, exerciseIDs []string) (orm.SetSlice, error) { rawQuery := ` - SELECT * FROM getstronger.sets WHERE workout_id IN ( - SELECT DISTINCT ON (exercise_id) workout_id - FROM getstronger.sets - WHERE exercise_id = ANY ($1) +SELECT * FROM getstronger.sets WHERE (exercise_id, workout_id) IN ( + SELECT exercise_id, workout_id FROM ( + SELECT DISTINCT ON (exercise_id) exercise_id, workout_id + FROM getstronger.sets + WHERE exercise_id = ANY($1) ORDER BY exercise_id, created_at DESC - ) ORDER BY created_at; + ) as previous_sets +) +ORDER BY created_at; ` var sets orm.SetSlice diff --git a/server/testing/factory/factory_workout.go b/server/testing/factory/factory_workout.go index 41f3d915..9aba3d3f 100644 --- a/server/testing/factory/factory_workout.go +++ b/server/testing/factory/factory_workout.go @@ -101,3 +101,9 @@ func WorkoutName(name string) WorkoutOpt { workout.Name = name } } + +func WorkoutCreatedAt(createdAt time.Time) WorkoutOpt { + return func(workout *orm.Workout) { + workout.CreatedAt = createdAt + } +} diff --git a/web/src/ui/components/AppButton.vue b/web/src/ui/components/AppButton.vue index d756c8e9..f2f3aeab 100644 --- a/web/src/ui/components/AppButton.vue +++ b/web/src/ui/components/AppButton.vue @@ -2,7 +2,7 @@ import { computed } from 'vue' const props = defineProps<{ - colour: 'amber' | 'gray' | 'green' | 'primary' | 'red' + colour: 'amber' | 'gray' | 'green' | 'primary' | 'red' | 'black' containerClass?: string to?: string type: 'button' | 'link' | 'submit' @@ -57,4 +57,8 @@ button { .gray { @apply bg-gray-200 border-b-0 py-4 focus-visible:outline-gray-500 text-gray-500; } + +.black { + @apply bg-gray-800 border-b-black text-white; +} diff --git a/web/src/ui/components/AppList.vue b/web/src/ui/components/AppList.vue index 2ab5dee9..0b186ec6 100644 --- a/web/src/ui/components/AppList.vue +++ b/web/src/ui/components/AppList.vue @@ -1,7 +1,6 @@