fugly mugly
This commit is contained in:
parent
d8b600a74e
commit
0b34ef5f3d
20
src/App.tsx
20
src/App.tsx
@ -4,14 +4,20 @@ import Header from "./components/Header";
|
|||||||
import WorkoutSelector from "./components/WorkoutSelector";
|
import WorkoutSelector from "./components/WorkoutSelector";
|
||||||
import { CurrentExerciseType, ExerciseInfosType } from "./types";
|
import { CurrentExerciseType, ExerciseInfosType } from "./types";
|
||||||
|
|
||||||
enum Stat { Reps, Sets, Weight, Time, Steps, MaxHR, AvgHR, StepsPerMin };
|
export enum Stat { Reps, Sets, Weight, Time, Steps, MaxHR, AvgHR, StepsPerMin };
|
||||||
|
|
||||||
function statLength() {
|
export function statLength() {
|
||||||
return Object.keys(Stat).length / 2;
|
return Object.keys(Stat).length / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const exerciseInfos: ExerciseInfosType = {
|
export const exerciseInfos: ExerciseInfosType = {
|
||||||
Squat: {
|
"Squat": {
|
||||||
|
defaultStats: [Stat.Reps, Stat.Sets, Stat.Weight]
|
||||||
|
},
|
||||||
|
"Deadlift": {
|
||||||
|
defaultStats: [Stat.Reps, Stat.Sets, Stat.Weight]
|
||||||
|
},
|
||||||
|
"Bench Press": {
|
||||||
defaultStats: [Stat.Reps, Stat.Sets, Stat.Weight]
|
defaultStats: [Stat.Reps, Stat.Sets, Stat.Weight]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,9 +50,9 @@ function App() {
|
|||||||
const l = statLength();
|
const l = statLength();
|
||||||
for (let i = 0; i < l; i++) {
|
for (let i = 0; i < l; i++) {
|
||||||
if (currentExercises[addIndex].stats[Stat[i]] === undefined) {
|
if (currentExercises[addIndex].stats[Stat[i]] === undefined) {
|
||||||
currentExercises[addIndex].stats[Stat[i]] = null;
|
var newExercises = [...currentExercises];
|
||||||
console.log(currentExercises);
|
newExercises[addIndex].stats[Stat[i]] = null;
|
||||||
setExercises(currentExercises);
|
setExercises(newExercises);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
import { exerciseInfos } from "../App";
|
||||||
import { CurrentExerciseType } from "../types";
|
import { CurrentExerciseType } from "../types";
|
||||||
import InputStat from "./InputStat";
|
import InputStat from "./InputStat";
|
||||||
|
|
||||||
function Exercise({ currentExercise, deleteCurrentExercise, addStat }: { currentExercise: CurrentExerciseType, deleteCurrentExercise: () => void, addStat: () => void }) {
|
function Exercise({ currentExercise, deleteCurrentExercise, addStat }: { currentExercise: CurrentExerciseType, deleteCurrentExercise: () => void, addStat: () => void }) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
Exercise :<select></select>
|
Exercise :<select>
|
||||||
|
{Object.keys(exerciseInfos).map((exerciseName, index) => <option key={index} value={exerciseName}>{exerciseName}</option>)}
|
||||||
|
</select>
|
||||||
{Object.entries(currentExercise.stats).map(([stat, value], index) => <InputStat key={index} stat={stat} />)}
|
{Object.entries(currentExercise.stats).map(([stat, value], index) => <InputStat key={index} stat={stat} />)}
|
||||||
<button onClick={addStat}>Add Stat</button>
|
<button onClick={addStat}>Add Stat</button>
|
||||||
<button onClick={deleteCurrentExercise}>Delete</button>
|
<button onClick={deleteCurrentExercise}>Delete</button>
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
import { Stat, statLength } from "../App";
|
||||||
function InputStat({ stat, statType }: { stat: string, statType?: string }) {
|
function InputStat({ stat, statType }: { stat: string, statType?: string }) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<select>{stat}</select>: <input type={(statType === undefined ? 'number' : statType)} />
|
<select>
|
||||||
|
{Object.keys(Stat).filter((_, index) => index < statLength()).map((_, index) => <option key={index} value={Stat[index]}>{Stat[index]}</option>)}
|
||||||
|
</select>: <input type={(statType === undefined ? 'number' : statType)} />
|
||||||
</div >
|
</div >
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user