Skip to content

Commit

Permalink
Merge pull request #145 from WhyAsh5114/144-myorep-match-down-sets
Browse files Browse the repository at this point in the history
Myorep match down sets
  • Loading branch information
WhyAsh5114 authored Nov 14, 2024
2 parents 795efec + 4a77790 commit 53d3c97
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "SetType" ADD VALUE 'MyorepMatchDown';
1 change: 1 addition & 0 deletions prisma/schema/enums.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum SetType {
Down
Myorep
MyorepMatch
MyorepMatchDown
}

enum ChangeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,16 @@
</Select.Content>
</Select.Root>
</div>
{#if currentExercise.setType === 'Drop' || currentExercise.setType === 'Down'}
{#if currentExercise.setType === 'Drop' || currentExercise.setType === 'Down' || currentExercise.setType === 'MyorepMatchDown'}
<div class="flex w-full flex-col gap-1.5">
<Select.Root
name="exercise-set-change-type"
onSelectedChange={(v) => {
if (currentExercise.setType === 'Drop' || currentExercise.setType === 'Down')
if (
currentExercise.setType === 'Drop' ||
currentExercise.setType === 'Down' ||
currentExercise.setType === 'MyorepMatchDown'
)
currentExercise.changeType = v?.value ?? 'Percentage';
}}
required
Expand Down
12 changes: 10 additions & 2 deletions src/lib/utils/workoutUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,21 @@ export function createWorkoutExerciseInProgressFromMesocycleExerciseTemplate(
const newSets = oldSets ? [...oldSets] : [];
while (newSets.length < sets) newSets.push({ ...defaultSet, miniSets: [] });

if (exercise.setType !== 'Drop' && exercise.setType !== 'MyorepMatch') newSets.map((set) => (set.miniSets = []));
if (!['Drop', 'MyorepMatch', 'MyorepMatchDown'].includes(exercise.setType)) {
newSets.map((set) => (set.miniSets = []));
}

if (!['Drop', 'Down', 'Top'].includes(exercise.setType)) {
if (!['Drop', 'Down', 'MyorepMatchDown'].includes(exercise.setType)) {
exercise.changeAmount = null;
exercise.changeType = null;
}

if (['Straight', 'MyorepMatch'].includes(exercise.setType)) {
newSets.map((set, setIndex) => {
if (setIndex) set.load = newSets[0].load;
});
}

return { ...exercise, sets: newSets.slice(0, sets) };
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/zodSchemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const MuscleGroupSchema = z.enum(['Chest','FrontDelts','SideDelts','RearD

export type MuscleGroupType = `${z.infer<typeof MuscleGroupSchema>}`

export const SetTypeSchema = z.enum(['Straight','V2','Drop','Down','Myorep','MyorepMatch']);
export const SetTypeSchema = z.enum(['Straight','V2','Drop','Down','Myorep','MyorepMatch','MyorepMatchDown']);

export type SetTypeType = `${z.infer<typeof SetTypeSchema>}`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@
}
function addMiniSet(setIndex: number) {
let load: undefined | number;
if (exercise.setType === 'MyorepMatch') load = exercise.sets[0].load;
if (exercise.setType === 'MyorepMatchDown') load = exercise.sets[setIndex].load;
exercise.sets[setIndex].miniSets.push({
completed: false,
reps: undefined,
load: exercise.setType === 'MyorepMatch' ? exercise.sets[0].load : undefined,
load,
RIR: undefined
});
}
function completeMiniSet(e: SubmitEvent, set: WorkoutExerciseSet, miniSetIndex: number) {
e.preventDefault();
if (exercise.setType === 'MyorepMatchDown') set.miniSets[miniSetIndex].load = set.load;
set.miniSets[miniSetIndex].completed = !set.miniSets[miniSetIndex].completed;
workoutRunes.workoutExercises = workoutRunes.workoutExercises;
}
Expand Down Expand Up @@ -250,7 +254,7 @@
</Button>
</div>
</form>
{#if (idx > 0 && exercise.setType === 'MyorepMatch') || exercise.setType === 'Drop'}
{#if (idx > 0 && (exercise.setType === 'MyorepMatch' || exercise.setType === 'MyorepMatchDown')) || exercise.setType === 'Drop'}
{#each set.miniSets as miniSet, miniIdx}
{@const miniSetButtonDisabled = shouldMiniSetBeDisabled(idx, miniIdx)}
{#if set.skipped}
Expand All @@ -272,7 +276,7 @@
type="number"
bind:value={miniSet.reps}
/>
{#if exercise.setType === 'MyorepMatch'}
{#if exercise.setType === 'MyorepMatch' || exercise.setType === 'MyorepMatchDown'}
<span></span>
{:else}
{@const expectedLoad = getMiniSetLoad(idx, miniIdx)}
Expand Down Expand Up @@ -327,7 +331,7 @@
>
<RemoveIcon />
</Button>
{#if exercise.setType === 'MyorepMatch'}
{#if exercise.setType === 'MyorepMatch' || exercise.setType === 'MyorepMatchDown'}
{@const repsLeft = getRemainingMyorepMatchReps(idx)}
<span class="grid place-items-center text-sm font-medium text-primary">
{#if repsLeft && repsLeft > 0}
Expand Down
2 changes: 1 addition & 1 deletion tests/models/workouts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test('create workout with all set types', async ({ page }) => {
await page.getByRole('option', { name: 'Dumbbell bicep curls' }).click();
await page.getByLabel('Sets').fill('2');
await page.locator('button').filter({ hasText: 'Straight' }).click();
await page.getByRole('option', { name: 'Myorep match' }).click();
await page.getByRole('option', { name: 'Myorep match' }).first().click();
await page.getByRole('button', { name: 'Add exercise' }).click();

await page.locator('[id="Dumbbell\\ bicep\\ curls-set-1-reps"]').fill('12');
Expand Down

0 comments on commit 53d3c97

Please sign in to comment.