Skip to content

Commit

Permalink
bugfix: show correct day and cycle number
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Apr 21, 2024
1 parent d9ea6f7 commit cc8d986
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/lib/utils/mesocycles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export function getDayNumber(mesocycle: Mesocycle) {
return (mesocycle.workoutIds.length % mesocycle.splitLength) + 1;
export function getDayNumber(mesocycle: Mesocycle, workoutId?: string) {
const workoutIdx = workoutId
? mesocycle.workoutIds.findIndex((id) => id === workoutId)
: mesocycle.workoutIds.length;
return (workoutIdx % mesocycle.splitLength) + 1;
}

export function getCycleNumber(mesocycle: Mesocycle) {
return 1 + Math.floor(mesocycle.workoutIds.length / mesocycle.splitLength);
export function getCycleNumber(mesocycle: Mesocycle, workoutId?: string) {
const workoutIdx = workoutId
? mesocycle.workoutIds.findIndex((id) => id === workoutId)
: mesocycle.workoutIds.length;
return 1 + Math.floor(workoutIdx / mesocycle.splitLength);
}

export function getPlannedRIR(mesocycle: Mesocycle) {
Expand Down
13 changes: 11 additions & 2 deletions src/routes/workouts/view/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
import { page } from '$app/stores';
import { toast } from 'svelte-sonner';
import { getMuscleGroupsAndSets } from '$lib/utils/workouts';
import { getCycleNumber, getDayNumber } from '$lib/utils/mesocycles';
let workout: Workout | undefined;
let workout: WithSID<Workout> | undefined;
let mesocycle: WithSID<Mesocycle> | undefined;
let deleteConfirmDrawerOpen = false;
let callingEndpoint = false;
onMount(async () => {
const response = await fetch(`/api/workouts/${$page.params.id}`);
if (response.ok) {
workout = (await response.json()) as Workout;
workout = (await response.json()) as WithSID<Workout>;
const mesocycleResponse = await fetch(`/api/mesocycles/${workout.mesocycleId}`);
if (mesocycleResponse.ok) {
mesocycle = (await mesocycleResponse.json()) as WithSID<Mesocycle>;
Expand Down Expand Up @@ -103,7 +104,15 @@
<a class="font-medium underline" href="/mesocycles/view/{mesocycle._id}">
{mesocycle.name}
</a>
<span>
Day {getDayNumber(mesocycle, workout._id)}, Cycle {getCycleNumber(
mesocycle,
workout._id
)}
</span>
</div>
{:else}
<!-- TODO mesocycle only skeleton-->
{/if}
</div>
</Card.Content>
Expand Down

0 comments on commit cc8d986

Please sign in to comment.