Skip to content

Commit

Permalink
adding finish step
Browse files Browse the repository at this point in the history
  • Loading branch information
andorsk committed May 6, 2024
1 parent 0dfa821 commit f8c699e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
16 changes: 7 additions & 9 deletions src/components/workout/WorkoutManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,15 @@ export class WorkoutManager implements WorkoutManagerI {
}

async setStep(step: number) {
if (!this.workout || step < 0 || step > this.workout.steps.length) {
if (!this.workout || step < 0) {
throw new Error("Invalid step set. Must be valid and session created.");
}

if (this._currentStep >= this.workout.steps.length - 1) {
await this.endWorkout();
return;
}

this._set = true;
this._currentStep = step;
if (this._timer && this._workout) {
Expand All @@ -254,14 +260,6 @@ export class WorkoutManager implements WorkoutManagerI {
if (this.workout?.completed) {
return;
}
if (
this.workout &&
this.workout.steps &&
this._currentStep >= this.workout.steps.length - 1
) {
await this.endWorkout();
return;
}
await this.setStep(this._currentStep + 1);
}

Expand Down
12 changes: 11 additions & 1 deletion src/lib/workout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,23 @@ export const createSteps = (config: RoutineConfiguration): Step[] => {
steps.push({
name: config.CoolDown.name,
duration: config.CoolDown.duration,
color: "bg-blue-500",
color: "bg-teal-500",
cycle: 0,
totalSets: 1,
totalCycles: config.Cycles.value,
set: 0,
});

steps.push({
name: "Finish",
duration: 0,
color: "bg-blue-500",
cycle: 0,
totalSets: 0,
totalCycles: 0,
set: 0,
});

return steps;
};

Expand Down
7 changes: 6 additions & 1 deletion src/pages/PlayScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ function StepView() {
// workoutState.manager.ready,
// ]);

const whiteListedNames = ["Rest Between Sets", "Cool Down", "Preparation"];
const whiteListedNames = [
"Rest Between Sets",
"Cool Down",
"Preparation",
"Finish",
];

return (
<div className="overflow-y-auto">
Expand Down

0 comments on commit f8c699e

Please sign in to comment.