From d8b600a74e6c34bc6a245cf8043b46f2ed774f91 Mon Sep 17 00:00:00 2001 From: Jesko Dujmovic Date: Sun, 9 Jan 2022 22:13:33 +0100 Subject: [PATCH] change --- src/App.tsx | 30 ++++++++++++++++++++++-------- src/types.d.ts | 8 ++++++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d577cd4..a8d722d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,13 +2,22 @@ import { useState } from "react"; import Exercises from "./components/Exercises"; import Header from "./components/Header"; import WorkoutSelector from "./components/WorkoutSelector"; -import { CurrentExerciseType } from "./types"; - +import { CurrentExerciseType, ExerciseInfosType } from "./types"; enum Stat { Reps, Sets, Weight, Time, Steps, MaxHR, AvgHR, StepsPerMin }; +function statLength() { + return Object.keys(Stat).length / 2; +} + +const exerciseInfos: ExerciseInfosType = { + Squat: { + defaultStats: [Stat.Reps, Stat.Sets, Stat.Weight] + } +} + function App() { - const [currentExercises, setExercises]: [CurrentExerciseType[], any] = useState([ + const [currentExercises, setExercises] = useState([ { name: "Squat", stats: { "Weight": 10 } @@ -28,15 +37,20 @@ function App() { { name: "Squat", stats: {} - }]) + }]); } function addStat(addIndex: number) { - for (const checkStat in Stat) { - //console.log(checkStat, typeof (checkStat)); + const l = statLength(); + for (let i = 0; i < l; i++) { + if (currentExercises[addIndex].stats[Stat[i]] === undefined) { + currentExercises[addIndex].stats[Stat[i]] = null; + console.log(currentExercises); + setExercises(currentExercises); + return; + } + } - console.log(currentExercises[addIndex].stats) - //setExercises([..]) } diff --git a/src/types.d.ts b/src/types.d.ts index b4676a0..d45be75 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,4 +1,8 @@ export type CurrentExerciseType = { name: string, - stats: { [stat: Stat]: any }, -}; \ No newline at end of file + stats: { [stat: string]: any }, +}; + +export type ExerciseInfosType = { + [key: string]: { defaultStats: Stat[] } +}