From 08f133c662d39a7b41446330956344f1afc9bb72 Mon Sep 17 00:00:00 2001 From: WhyAsh5114 Date: Sat, 19 Oct 2024 00:06:55 +0530 Subject: [PATCH] fix: update migration function to fix the deleted template bug --- src/lib/trpc/routes/users.ts | 3 +- .../(components)/MesocycleSplitTab.svelte | 56 ++++++++++--------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/lib/trpc/routes/users.ts b/src/lib/trpc/routes/users.ts index e5bdfccd..b20572e7 100644 --- a/src/lib/trpc/routes/users.ts +++ b/src/lib/trpc/routes/users.ts @@ -218,7 +218,8 @@ export const users = t.router({ startOverloadPercentage: 0, userId: ctx.userId, exerciseSplitId: templateIdx ? mesocycleTemplateIds[templateIdx] : null, - RIRProgression: mesocycleTemplates[templateIdx].RIRProgression.map(({ cycles }) => cycles) + RIRProgression: + templateIdx === -1 ? [1] : mesocycleTemplates[templateIdx].RIRProgression.map(({ cycles }) => cycles) }; if (firstWorkout) { diff --git a/src/routes/mesocycles/[mesocycleId]/(components)/MesocycleSplitTab.svelte b/src/routes/mesocycles/[mesocycleId]/(components)/MesocycleSplitTab.svelte index 810a58c9..dc58ba9a 100644 --- a/src/routes/mesocycles/[mesocycleId]/(components)/MesocycleSplitTab.svelte +++ b/src/routes/mesocycles/[mesocycleId]/(components)/MesocycleSplitTab.svelte @@ -17,29 +17,33 @@ } - - The current split of the mesocycle - - - { - selectedSplitDay = mesocycle.mesocycleExerciseSplitDays.find((splitDay) => splitDay.name === v)!; - }} - value={selectedSplitDay.name} -> - - {#each mesocycle.mesocycleExerciseSplitDays as splitDay} - - {splitDay.isRestDay ? 'Rest' : splitDay.name} - - {/each} - - - {#each selectedSplitDay.mesocycleSplitDayExercises as exercise} - - {/each} - - +{#if mesocycle.mesocycleExerciseSplitDays.length > 0} + + The current split of the mesocycle + + + { + selectedSplitDay = mesocycle.mesocycleExerciseSplitDays.find((splitDay) => splitDay.name === v)!; + }} + value={selectedSplitDay.name} + > + + {#each mesocycle.mesocycleExerciseSplitDays as splitDay} + + {splitDay.isRestDay ? 'Rest' : splitDay.name} + + {/each} + + + {#each selectedSplitDay.mesocycleSplitDayExercises as exercise} + + {/each} + + +{:else} +
Mesocycle template for this mesocycle in V2 seems to have been deleted
+{/if}