Skip to content

Commit

Permalink
feat: show Date in <WorkoutExerciseCard> in ExerciseHistory and Exe…
Browse files Browse the repository at this point in the history
…rciseStats
  • Loading branch information
WhyAsh5114 committed Dec 27, 2024
1 parent 222b9a1 commit 33c51fa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/routes/exercise-stats/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
let selectedExercise = $state<string>();
let exerciseInstances = $state<WorkoutExercise[]>();
let filteredExercisesByMuscleGroup = $derived(
exercisesByMuscleGroup
?.filter((g) => g.exercises.some((ex) => ex.name.toLowerCase().includes(searchText)))
.map(({ group, exercises }) => ({
group,
exercises: exercises.filter((ex) => ex.name.toLowerCase().includes(searchText))
})) ?? []
);
onMount(async () => {
const exerciseList = await data.exerciseList;
exercisesByMuscleGroup = Object.entries(
Expand Down Expand Up @@ -50,7 +59,7 @@
</Button>
</Popover.Trigger>
<Popover.Content sameWidth>
<Command.Root class="mb-6 h-fit">
<Command.Root class="mb-6 h-fit" shouldFilter={false}>
<Command.Input placeholder="Type here" bind:value={searchText} />
<Command.List>
{#if exercisesByMuscleGroup === undefined}
Expand All @@ -64,7 +73,7 @@
</Command.Loading>
{:else}
<Command.Empty>No results found.</Command.Empty>
{#each exercisesByMuscleGroup as { exercises, group }}
{#each filteredExercisesByMuscleGroup as { group, exercises }}
<Command.Group heading={group}>
{#each exercises as ex}
<Command.Item onclick={() => selectExercise(ex.name)}>{ex.name}</Command.Item>
Expand All @@ -82,7 +91,7 @@
<ExerciseStatsChart {selectedExercise} exercises={exerciseInstances} />
{#if exerciseInstances}
{#each exerciseInstances as instance}
<WorkoutExerciseCard exercise={instance} />
<WorkoutExerciseCard exercise={instance} date={new Date(instance.workout.startedAt)} />
{/each}
{/if}
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/exercise-stats/ExerciseStatsChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
x: {
type: 'time',
time: {
unit: 'day',
unit: 'day'
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
exercise: Prisma.WorkoutExerciseGetPayload<{
include: { sets: { include: { miniSets: true } } };
}>;
date?: Date;
};
let { exercise }: PropsType = $props();
let { exercise, date }: 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">
<div class="flex items-center justify-between">
<span class="truncate">{exercise.name}</span>
{#if date}
<span class="text-sm text-muted-foreground">
{new Date(date).toLocaleDateString()}
</span>
{/if}
</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 @@ -68,7 +68,7 @@
})}
</span>
</div>
<WorkoutExerciseCard {exercise} />
<WorkoutExerciseCard {exercise} date={new Date(exercise.workout.startedAt)} />
{/each}
<DefaultInfiniteLoader {loadMore} identifier={workoutRunes.exerciseHistorySheetName} entityPlural="exercises" />
</div>
Expand Down

0 comments on commit 33c51fa

Please sign in to comment.