diff --git a/src/components/App.tsx b/src/components/App.tsx index c826382..89340b5 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import CongratsPage from './shared/Congratulations'; import ExerciseSide from './shared/ExerciseSide'; import LessonSide from './shared/LessonSide/LessonSide'; @@ -6,12 +6,24 @@ import '../assets/WestwoodSans-Regular.ttf'; function App(): JSX.Element { const [exerciseCount, setExerciseCount] = useState(0); - // const [completeExercises, setCompleteExercises] = useState(0); + const [completeExercises, setCompleteExercises] = useState(1); + + //update complete if exercise changes + useEffect(() => { + updateComplete(); + }, [exerciseCount]); const updateLevel = (newLevel: number): void => { setExerciseCount(newLevel - 1); }; + const updateComplete = (): void => { + // console.log(exerciseCount); + if (exerciseCount >= completeExercises) { + setCompleteExercises(completeExercises + 1); + } + }; + if (exerciseCount == 5) { return (
@@ -22,7 +34,11 @@ function App(): JSX.Element { return (
- + setExerciseCount(exerciseCount + 1)} diff --git a/src/components/shared/ExerciseSide.tsx b/src/components/shared/ExerciseSide.tsx index c8a80cb..7cccd1e 100644 --- a/src/components/shared/ExerciseSide.tsx +++ b/src/components/shared/ExerciseSide.tsx @@ -15,13 +15,16 @@ import UnitCircleInput from './Exercises/UnitCircleInput'; interface ExerciseSideProps { ExercisesNum: number; incrementExercise: () => void; + // maxLevel: number } function ExerciseSide({ incrementExercise, ExercisesNum, -}: ExerciseSideProps): JSX.Element { - const [completeExercises, setCompleteExercises] = useState(0); +}: // maxLevel, +ExerciseSideProps): JSX.Element { + const [displayExercise, setDisplayExercise] = useState(0); + type availableExercises = 'axis' | 'congrats' | 'graph' | 'unitcircle'; const exercises: availableExercises[] = [ @@ -32,11 +35,11 @@ function ExerciseSide({ ]; let curExercise; - if (completeExercises != ExercisesNum) { - setCompleteExercises(ExercisesNum); + if (displayExercise != ExercisesNum) { + setDisplayExercise(ExercisesNum); } - if (exercises[completeExercises] == 'graph') { + if (exercises[displayExercise] == 'graph') { curExercise = (
@@ -118,7 +121,7 @@ function ExerciseSide({ />
);*/ - } else if (exercises[completeExercises] == 'axis') { + } else if (exercises[displayExercise] == 'axis') { curExercise = (
{ - setCompleteExercises(completeExercises + 1); + setDisplayExercise(displayExercise + 1); incrementExercise(); return; }} />
); - } else if (exercises[completeExercises] === 'unitcircle') { + } else if (exercises[displayExercise] === 'unitcircle') { curExercise = (
@@ -149,7 +152,8 @@ function ExerciseSide({ /> { - setCompleteExercises(completeExercises + 1); + // console.log('unit'); + setDisplayExercise(displayExercise + 1); incrementExercise(); return; }} diff --git a/src/components/shared/Exercises/AxisParent.tsx b/src/components/shared/Exercises/AxisParent.tsx index 7dcad68..0e99234 100644 --- a/src/components/shared/Exercises/AxisParent.tsx +++ b/src/components/shared/Exercises/AxisParent.tsx @@ -55,7 +55,7 @@ function AxisParent({ if (exerciseNum == axisMarkers.length) { toNextExercise(); // update parent exercise side that axis input exercise is complete } - }); + }, [exerciseNum]); return (
diff --git a/src/components/shared/LessonSide/LessonSide.tsx b/src/components/shared/LessonSide/LessonSide.tsx index d598084..1158d08 100644 --- a/src/components/shared/LessonSide/LessonSide.tsx +++ b/src/components/shared/LessonSide/LessonSide.tsx @@ -9,10 +9,16 @@ import Turtle from './Turtle'; interface lessonSideProps { levelNum: number; updateLevel: (newCount: number) => void; + maxLevel: number; } -function LessonSide({ levelNum, updateLevel }: lessonSideProps): JSX.Element { +function LessonSide({ + levelNum, + updateLevel, + maxLevel, +}: lessonSideProps): JSX.Element { const lesson_info = LessonSideContent[levelNum] || []; + // console.log("max:" + maxLevel); return (
@@ -33,7 +39,7 @@ function LessonSide({ levelNum, updateLevel }: lessonSideProps): JSX.Element {
diff --git a/src/components/shared/LessonSide/LevelSelector.tsx b/src/components/shared/LessonSide/LevelSelector.tsx index 2eb7be2..4b3f761 100644 --- a/src/components/shared/LessonSide/LevelSelector.tsx +++ b/src/components/shared/LessonSide/LevelSelector.tsx @@ -30,7 +30,7 @@ function LevelSelector({ // If index is even, add a level button. Else, add a level connector. return i % 2 == 0 ? (
handleLevelClick(level)} className={ 'level-button' + @@ -43,7 +43,7 @@ function LevelSelector({
);