diff --git a/src/components/shared/ExerciseSide.tsx b/src/components/shared/ExerciseSide.tsx index b28f618..d55d764 100644 --- a/src/components/shared/ExerciseSide.tsx +++ b/src/components/shared/ExerciseSide.tsx @@ -25,12 +25,17 @@ function ExerciseSide({ ExerciseSideProps): JSX.Element { const [displayExercise, setDisplayExercise] = useState(0); - type availableExercises = 'axis' | 'congrats' | 'graph' | 'unitcircle'; + type availableExercises = + | 'axis' + | 'congrats' + | 'graph0' + | 'unitcircle' + | 'graph1'; const exercises: availableExercises[] = [ 'unitcircle', 'axis', - 'graph', + 'graph0', 'congrats', ]; let curExercise; @@ -39,20 +44,20 @@ ExerciseSideProps): JSX.Element { setDisplayExercise(ExercisesNum); } - if (exercises[displayExercise] == 'graph') { + if (exercises[displayExercise] == 'graph0') { curExercise = (
@@ -69,30 +74,30 @@ ExerciseSideProps): JSX.Element { { textArray: [ { type: 'text', text: 'turtle.goto(' }, - { type: 'input', width: 2 }, - { type: 'text', text: ', -1)' }, + { type: 'input', width: 2, id: 0, answer: '2' }, + { type: 'text', text: ', 1)' }, ], }, { textArray: [ { type: 'text', text: 'turtle.setheading(' }, - { type: 'input', width: 4 }, + { type: 'input', width: 4, id: 1, answer: '225' }, { type: 'text', text: ')' }, ], }, { textArray: [ { type: 'text', text: 'turtle.' }, - { type: 'input', width: 8 }, + { type: 'input', width: 8, id: 2, answer: 'forward' }, { type: 'text', text: '()' }, ], }, { textArray: [ { type: 'text', text: 'turtle.goto(' }, - { type: 'input', width: 2 }, + { type: 'input', width: 2, id: 3, answer: '0' }, { type: 'text', text: ', ' }, - { type: 'input', width: 2 }, + { type: 'input', width: 2, id: 4, answer: '-1' }, { type: 'text', text: ')' }, ], }, @@ -121,6 +126,69 @@ ExerciseSideProps): JSX.Element { />
);*/ + } else if (exercises[displayExercise] == 'graph1') { + curExercise = ( +
+
+ +
+
+ incrementExercise()} + /> +
+
+ ); } else if (exercises[displayExercise] == 'axis') { curExercise = (
diff --git a/src/components/shared/Exercises/GraphExercise.tsx b/src/components/shared/Exercises/GraphExercise.tsx index ca3be1f..cefab0b 100644 --- a/src/components/shared/Exercises/GraphExercise.tsx +++ b/src/components/shared/Exercises/GraphExercise.tsx @@ -128,7 +128,7 @@ GraphProps): JSX.Element { const dyPercent = yPos(endY) - yPos(startY); // use this factor because dyPercent is relative to height, // but we express a line's length as a percentage of width. - const yxRatio = 22.5 / 40; + const yxRatio = 22.5 / 50; const lineLengthPercent = Math.sqrt( (dxPercent / 100) ** 2 + ((dyPercent * yxRatio) / 100) ** 2 diff --git a/src/components/shared/Exercises/GraphInput.tsx b/src/components/shared/Exercises/GraphInput.tsx index a20c5ba..b3d9a39 100644 --- a/src/components/shared/Exercises/GraphInput.tsx +++ b/src/components/shared/Exercises/GraphInput.tsx @@ -1,49 +1,76 @@ +//import { useState } from 'react'; +//import { useState } from 'react'; import '../../../styles/Exercises/GraphInput.scss'; -interface GraphQuestionElement { +interface GraphQuestionData { type: string; text?: string; width?: number; answer?: string; + id?: number; } -interface GraphQuestion { - textArray: GraphQuestionElement[]; +interface GraphQuestionGrouping { + questionData: GraphQuestionData; + setCorrect: (id: number, value: boolean) => void; +} + +interface GraphLineGrouping { + data: GraphLineData; + setCorrect: (id: number, value: boolean) => void; } interface GraphInputProps { - questionArray: GraphQuestion[]; + questionArray: GraphLineData[]; nextExercise: () => void; } -function GraphStringElement({ type, text, width }: GraphQuestionElement) { - if (type == 'text') { - return

{text}

; +interface GraphLineData { + textArray: GraphQuestionData[]; +} + +function GraphStringElement({ + questionData, + setCorrect, +}: GraphQuestionGrouping) { + if (questionData.type == 'text') { + return

{questionData?.text ?? ''}

; } else { + //const [inputText, setInputText] = useState(""); + const handleChange = (event: { target: { value: string } }) => { + //console.log(`input text: ${event.target.value}`); + //console.log(questionData?.answer ?? ''); + if (event.target.value == (questionData?.answer ?? '')) { + setCorrect(questionData?.id ?? -1, true); + } else { + setCorrect(questionData?.id ?? -1, false); + } + //setInputText(event.target.value); + }; return ( - +
+ +
); } } -function GraphLine({ textArray }: GraphQuestion) { +function GraphLine({ data, setCorrect }: GraphLineGrouping) { //Map all elements of TextArray - const makeElement = (elementData: GraphQuestionElement): JSX.Element => { + const makeElement = (elementData: GraphQuestionData): JSX.Element => { return ( - + ); }; return ( -
{textArray.map(makeElement)}
+
+ {data.textArray.map(makeElement)} +
); /*return (
@@ -58,8 +85,39 @@ function GraphInput({ questionArray, nextExercise, }: GraphInputProps): JSX.Element { - const makeLine = (lineArray: GraphQuestion): JSX.Element => { - return ; + const valueMap = new Map(); + for (const question of questionArray) { + for (const item of question.textArray) { + if (item.type == 'input') { + valueMap.set(item.id ?? -1, false); + } + } + } + const setValueCorrect = (id: number, value: boolean): void => { + //console.log(`Setting ${id} to ${value}`); + valueMap.set(id, value); + }; + + const checkCorrect = (): void => { + //console.log('Checking correct'); + const valuesArray = Array.from(valueMap.values()); + for (const i of valuesArray) { + //console.log(i); + if (!i) { + //console.log(`${i} is incorrect`); + //setWrong(true); + return; + } + } + //console.log('all right!'); + nextExercise(); + }; + + const makeLine = ( + data: GraphLineData, + setCorrect: (id: number, value: boolean) => void + ): JSX.Element => { + return ; }; return (
@@ -67,27 +125,16 @@ function GraphInput({ Fill in the blanks to move the cursor along the path!
-
{questionArray.map(makeLine)}
+
+ {questionArray.map((x) => makeLine(x, setValueCorrect))} +
-
); - /* - return ( -
-
- -
-
- );*/ } export default GraphInput; diff --git a/src/styles/Exercises/GraphInput.scss b/src/styles/Exercises/GraphInput.scss index 3f6b1a2..a561dd7 100644 --- a/src/styles/Exercises/GraphInput.scss +++ b/src/styles/Exercises/GraphInput.scss @@ -22,8 +22,9 @@ font-style: normal; font-weight: bold; margin-bottom: 2vh; - margin-left: -20px; + margin-left: 0; margin-right: auto; + margin-top: 100px; padding-left: 8%; } diff --git a/src/styles/Graph.scss b/src/styles/Graph.scss index 6a182fc..6df3344 100644 --- a/src/styles/Graph.scss +++ b/src/styles/Graph.scss @@ -1,14 +1,15 @@ .graph-container { align-items: center; - border: solid 2px #000; + border: solid 1px rgb(209, 209, 209); border-radius: 12px; height: 0; + margin-left: 5%; // If editing the sizing of graph-container (padding-bottom or width), // modify the value of `yxRatio` in Graph.tsx padding-bottom: 22.5%; position: absolute; top: 5%; - width: 40%; // see above warning + width: 50%; // see above warning } .grid-line {