From 0fb8b96e61da52151e92802f1e747896422bb246 Mon Sep 17 00:00:00 2001 From: WhyAsh5114 Date: Thu, 20 Jun 2024 18:25:20 +0530 Subject: [PATCH] implemented edit and clone of mesocycle --- .../mesocycles/manage/volume/+page.svelte | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/routes/mesocycles/manage/volume/+page.svelte b/src/routes/mesocycles/manage/volume/+page.svelte index 726920f9..785e137b 100644 --- a/src/routes/mesocycles/manage/volume/+page.svelte +++ b/src/routes/mesocycles/manage/volume/+page.svelte @@ -31,22 +31,30 @@ const id = mesocycleRunes.editingMesocycleId; savingMesocycle = true; - mesocycleRunes.distributeStartVolumes(); - const exerciseSplit = mesocycleRunes.selectedExerciseSplit as FullExerciseSplit; - const exerciseSplitWithoutExercises = { - ...exerciseSplit, - exerciseSplitDays: exerciseSplit.exerciseSplitDays.map((splitDay) => { - const { exercises, id, exerciseSplitId, ...rest } = splitDay; - return rest; - }) - }; const mesocycleCyclicSetChanges = mesocycleRunes.mesocycleCyclicSetChanges.map((setChange) => { const { startVolume, inSplit, ...rest } = setChange; return rest; }); if (id) { + const { message } = await trpc().mesocycles.editById.mutate({ + id, + mesocycleData: { + mesocycle: mesocycleRunes.mesocycle, + mesocycleCyclicSetChanges + } + }); + toast.success(message); } else { + mesocycleRunes.distributeStartVolumes(); + const exerciseSplit = mesocycleRunes.selectedExerciseSplit as FullExerciseSplit; + const exerciseSplitWithoutExercises = { + ...exerciseSplit, + exerciseSplitDays: exerciseSplit.exerciseSplitDays.map((splitDay) => { + const { exercises, id, exerciseSplitId, ...rest } = splitDay; + return rest; + }) + }; const { message } = await trpc().mesocycles.create.mutate({ mesocycle: { ...mesocycleRunes.mesocycle, @@ -57,8 +65,8 @@ exerciseSplit: exerciseSplitWithoutExercises }); toast.success(message); - await invalidate('mesocycles:all'); } + await invalidate('mesocycles:all'); await goto('/mesocycles'); savingMesocycle = false; mesocycleRunes.resetStores(); @@ -71,7 +79,7 @@
- +