From 6e145566c174f641a16cec66d8d76e78d586b3b9 Mon Sep 17 00:00:00 2001 From: WhyAsh5114 Date: Tue, 24 Dec 2024 00:17:11 +0530 Subject: [PATCH] feat: added full exercise history and graphs --- src/lib/trpc/routes/workouts.ts | 1 + .../(components)/layout/NavLinks.svelte | 1 + src/routes/exercise-stats/+page.server.ts | 15 ++ src/routes/exercise-stats/+page.svelte | 89 +++++++++++ .../exercise-stats/ExerciseStatsChart.svelte | 144 ++++++++++++++++++ 5 files changed, 250 insertions(+) create mode 100644 src/routes/exercise-stats/+page.server.ts create mode 100644 src/routes/exercise-stats/+page.svelte create mode 100644 src/routes/exercise-stats/ExerciseStatsChart.svelte diff --git a/src/lib/trpc/routes/workouts.ts b/src/lib/trpc/routes/workouts.ts index 79613e01..b6abefc2 100644 --- a/src/lib/trpc/routes/workouts.ts +++ b/src/lib/trpc/routes/workouts.ts @@ -645,6 +645,7 @@ export const workouts = t.router({ workout: { select: { startedAt: true, + userBodyweight: true, workoutOfMesocycle: { select: { splitDayIndex: true, diff --git a/src/routes/(components)/layout/NavLinks.svelte b/src/routes/(components)/layout/NavLinks.svelte index 6f684bcd..f189dae2 100644 --- a/src/routes/(components)/layout/NavLinks.svelte +++ b/src/routes/(components)/layout/NavLinks.svelte @@ -7,6 +7,7 @@ const linkItems: ({ text: string; href: string } | null)[] = [ { text: 'Dashboard', href: '/dashboard' }, + { text: 'Exercise stats', href: '/exercise-stats' }, null, { text: 'Exercise splits', href: '/exercise-splits' }, { text: 'Mesocycles', href: '/mesocycles' }, diff --git a/src/routes/exercise-stats/+page.server.ts b/src/routes/exercise-stats/+page.server.ts new file mode 100644 index 00000000..d076e172 --- /dev/null +++ b/src/routes/exercise-stats/+page.server.ts @@ -0,0 +1,15 @@ +import { prisma } from '$lib/prisma.js'; +import { redirect } from '@sveltejs/kit'; + +export const load = async ({ parent }) => { + const { session } = await parent(); + if (!session) redirect(302, '/'); + + const exerciseList = prisma.workoutExercise.findMany({ + where: { workout: { userId: session.user!.id } }, + select: { name: true, targetMuscleGroup: true, customMuscleGroup: true }, + distinct: ['name'] + }); + + return { exerciseList }; +}; diff --git a/src/routes/exercise-stats/+page.svelte b/src/routes/exercise-stats/+page.svelte new file mode 100644 index 00000000..b89818d6 --- /dev/null +++ b/src/routes/exercise-stats/+page.svelte @@ -0,0 +1,89 @@ + + +

Exercise stats

+ + + + + + + + + + {#if exercisesByMuscleGroup === undefined} + +
+ + Fetching exercises... +
+
+ {:else} + No results found. + {#each exercisesByMuscleGroup as { exercises, group }} + + {#each exercises as ex} + selectExercise(ex.name)}>{ex.name} + {/each} + + {/each} + {/if} +
+
+
+
+ +
+ {#if selectedExercise} + + {#if exerciseInstances} + {#each exerciseInstances as instance} + + {/each} + {/if} + {/if} +
diff --git a/src/routes/exercise-stats/ExerciseStatsChart.svelte b/src/routes/exercise-stats/ExerciseStatsChart.svelte new file mode 100644 index 00000000..9e2e9e54 --- /dev/null +++ b/src/routes/exercise-stats/ExerciseStatsChart.svelte @@ -0,0 +1,144 @@ + + + + +
+ {selectedExercise} + + + + Chart type + +
+ + +
+
+ + +
+
+ + + + Sets to graph + + {#each Array.from({ length: maxSets }) as _, idx} + {idx + 1} + {/each} + +
+
+
+
+ + {#if exercises.length === 0} +
+ Fetching performances +
+ {:else} + + {/if} +
+