diff --git a/src/routes/mesocycles/[mesocycleId]/edit-split/mesocycleExerciseSplitRunes.svelte.ts b/src/routes/mesocycles/[mesocycleId]/edit-split/mesocycleExerciseSplitRunes.svelte.ts index aef48bad..75efa17e 100644 --- a/src/routes/mesocycles/[mesocycleId]/edit-split/mesocycleExerciseSplitRunes.svelte.ts +++ b/src/routes/mesocycles/[mesocycleId]/edit-split/mesocycleExerciseSplitRunes.svelte.ts @@ -1,4 +1,4 @@ -import type { Mesocycle, Prisma } from '@prisma/client'; +import type { Prisma } from '@prisma/client'; export type FullMesocycleWithExerciseSplit = Prisma.MesocycleGetPayload<{ include: { mesocycleExerciseSplitDays: { include: { mesocycleSplitDayExercises: true } } }; @@ -12,7 +12,7 @@ type MesocycleExerciseTemplateWithoutIds = Prisma.MesocycleExerciseTemplateCreateWithoutMesocycleExerciseSplitDayInput; export function createMesocycleExerciseSplitRunes() { - let mesocycle: Mesocycle | null = $state(null); + let mesocycle: FullMesocycleWithExerciseSplit | null = $state(null); let splitDays: MesocycleExerciseSplitDayWithoutIds[] = $state( Array.from({ length: 7 }).map(() => ({ name: '', isRestDay: false })) ); @@ -148,8 +148,7 @@ export function createMesocycleExerciseSplitRunes() { if (mesocycleWithExerciseSplit.id === mesocycle?.id) return; resetStores(); - const { mesocycleExerciseSplitDays, ...mesocycleData } = mesocycleWithExerciseSplit; - mesocycle = mesocycleData; + mesocycle = structuredClone($state.snapshot(mesocycleWithExerciseSplit)); splitDays = mesocycleWithExerciseSplit.mesocycleExerciseSplitDays.map((splitDay) => { const { id, mesocycleId, mesocycleSplitDayExercises, ...rest } = splitDay; return rest; diff --git a/src/routes/mesocycles/[mesocycleId]/edit-split/structure/+page.svelte b/src/routes/mesocycles/[mesocycleId]/edit-split/structure/+page.svelte index b54b2558..2920a1b9 100644 --- a/src/routes/mesocycles/[mesocycleId]/edit-split/structure/+page.svelte +++ b/src/routes/mesocycles/[mesocycleId]/edit-split/structure/+page.svelte @@ -2,18 +2,41 @@ import H3 from '$lib/components/ui/typography/H3.svelte'; import ResponsiveDialog from '$lib/components/ResponsiveDialog.svelte'; import * as Table from '$lib/components/ui/table'; + import * as Popover from '$lib/components/ui/popover'; import { Input } from '$lib/components/ui/input'; import { Button } from '$lib/components/ui/button'; import { Checkbox } from '$lib/components/ui/checkbox'; import AddIcon from 'virtual:icons/lucide/plus'; import RemoveIcon from 'virtual:icons/lucide/minus'; + import WarningIcon from 'virtual:icons/lucide/triangle-alert'; import { mesocycleExerciseSplitRunes } from '../mesocycleExerciseSplitRunes.svelte'; import { goto } from '$app/navigation'; import { toast } from 'svelte-sonner'; + import { cn } from '$lib/utils'; + const difference = (setA: Set, setB: Set): Set => { + return new Set([...setA].filter((x) => !setB.has(x))); + }; + + let consistencyLossDays: string[] = $state([]); let dataLossDays: number[] = $state([]); let warningDialogOpen = $state(false); + let showWarningIcon = $derived.by(() => { + if (mesocycleExerciseSplitRunes.mesocycle === null) return false; + const mesocycleSplitDayNames = new Set( + mesocycleExerciseSplitRunes.mesocycle?.mesocycleExerciseSplitDays.map( + (splitDay) => splitDay.name + ) + ); + const currentSplitDayNames = new Set( + mesocycleExerciseSplitRunes.splitDays.map((splitDay) => splitDay.name) + ); + const inconsistentDays = difference(mesocycleSplitDayNames, currentSplitDayNames); + consistencyLossDays = Array.from(inconsistentDays); + return inconsistentDays.size > 0; + }); + async function submitStructure(warningAcknowledged = false) { if (!mesocycleExerciseSplitRunes.validateSplitStructure()) { toast.error('Workout names should be unique', { @@ -45,7 +68,26 @@ - + + + + + + + Unmatched day names: + {consistencyLossDays.join(', ')} + +
+

+ Avoid unnecessarily changing split day names, as this can exclude workouts with + unmatched split names from progression calculations and analytics. +

+
+
+
Name Rest
@@ -53,7 +95,7 @@ {#each mesocycleExerciseSplitRunes.splitDays as splitDay, dayNumber} - {dayNumber + 1} + {dayNumber + 1}