Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Myorep match down sets #145

Merged
merged 6 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading