Skip to content

Commit

Permalink
UI changes, and added rep load copy action button
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Aug 4, 2024
1 parent f5ca36c commit 74d3b16
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
20 changes: 19 additions & 1 deletion src/lib/trpc/routes/workouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,25 @@ export const workouts = t.router({
return await prisma.workoutExercise.findMany({
where: { workout: { userId: ctx.userId }, name: input.exerciseName },
include: {
workout: { select: { startedAt: true } },
workout: {
select: {
startedAt: true,
workoutOfMesocycle: {
select: {
splitDayIndex: true,
mesocycle: {
select: {
name: true,
mesocycleExerciseSplitDays: {
select: { name: true },
orderBy: { dayIndex: 'asc' }
}
}
}
}
}
}
},
sets: { include: { miniSets: true } }
},
cursor: input.cursorId !== undefined ? { id: input.cursorId } : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
exercise: Prisma.WorkoutExerciseGetPayload<{
include: { sets: { include: { miniSets: true } } };
}>;
workoutStartedAt?: Date;
};
let { exercise, workoutStartedAt }: PropsType = $props();
let { exercise }: PropsType = $props();
</script>

<div class="flex flex-col gap-0.5 rounded-md border bg-card/50 p-2 backdrop-blur-sm">
<div class="flex items-start justify-between">
<span class="truncate">{exercise.name}</span>
<span class="text-sm font-semibold text-muted-foreground">
{workoutStartedAt?.toLocaleDateString(undefined, { day: 'numeric', month: 'short' })}
</span>
</div>
<div class="flex items-center gap-0.5">
<span class="mr-auto text-sm lowercase text-muted-foreground">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import LoaderCircle from 'virtual:icons/lucide/loader-circle';
import { untrack } from 'svelte';
import WorkoutExerciseCard from '../../../[workoutId]/(components)/WorkoutExerciseCard.svelte';
import CopyIcon from 'virtual:icons/lucide/clipboard-copy';
let exercisesFound: RouterOutputs['workouts']['getExerciseHistory'] = $state([]);
Expand Down Expand Up @@ -49,8 +50,29 @@
triggerLoad={loadMore}
>
{#each exercisesFound as exercise}
<WorkoutExerciseCard {exercise} workoutStartedAt={exercise.workout.startedAt} />
<div class="mb-1"></div>
{@const wm = exercise.workout.workoutOfMesocycle}
<div class="mb-1 mt-4 flex items-start gap-1">
<Button
onclick={() => workoutRunes.copyExerciseSetNumbersFromHistory(exercise)}
size="icon"
variant="secondary"
>
<CopyIcon />
</Button>
<div class="mr-auto flex flex-col">
<span class="font-bold"
>{wm?.mesocycle.mesocycleExerciseSplitDays[wm.splitDayIndex].name}</span
>
<span class="text-xs font-semibold">{wm?.mesocycle.name}</span>
</div>
<span class="font-semibold text-muted-foreground">
{exercise.workout.startedAt.toLocaleDateString(undefined, {
day: 'numeric',
month: 'short'
})}
</span>
</div>
<WorkoutExerciseCard {exercise} />
{:else}
<div class="muted-text-box">No exercise history found</div>
{/each}
Expand Down
28 changes: 27 additions & 1 deletion src/routes/workouts/manage/workoutRunes.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type WorkoutExerciseInProgress,
type WorkoutExerciseWithSets
} from '$lib/workoutFunctions';
import type { Prisma } from '@prisma/client';
import type { FullWorkoutWithMesoData } from '../[workoutId]/+page.server';

type PreviousWorkoutData = {
Expand Down Expand Up @@ -95,6 +96,30 @@ function createWorkoutRunes() {
exerciseHistorySheetOpen = true;
}

function copyExerciseSetNumbersFromHistory(
exerciseFromHistory: Prisma.WorkoutExerciseGetPayload<{
include: { sets: { include: { miniSets: true } } };
}>
) {
const exerciseToEdit = workoutExercises?.find((ex) => ex.name === exerciseHistorySheetName);
if (!exerciseToEdit) return;

for (let i = 0; i < exerciseToEdit.sets.length; i++) {
if (!exerciseFromHistory.sets[i]) break;
const historySet = exerciseFromHistory.sets[i];
exerciseToEdit.sets[i] = {
...historySet,
completed: false,
miniSets: historySet.miniSets.map((miniSet) => ({
...miniSet,
completed: false
}))
};
}

exerciseHistorySheetOpen = false;
}

function loadWorkout(workout: FullWorkoutWithMesoData) {
editingWorkoutId = workout.id;
workoutData = {
Expand Down Expand Up @@ -175,7 +200,8 @@ function createWorkoutRunes() {
editExercise,
deleteExercise,
loadWorkout,
openExerciseHistorySheet
openExerciseHistorySheet,
copyExerciseSetNumbersFromHistory
};
}

Expand Down

0 comments on commit 74d3b16

Please sign in to comment.