Skip to content

Commit

Permalink
Merge branch 'main' into 87-feature-change-question-descriptions-to-m…
Browse files Browse the repository at this point in the history
…atch-the-actual-task
  • Loading branch information
SanjnaT41756 authored May 16, 2024
2 parents da6b8b0 + e02bbaf commit 0f03682
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 131 deletions.
130 changes: 102 additions & 28 deletions src/components/shared/ExerciseSide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import AxisParent from './Exercises/AxisParent';
import GraphExercise from './Exercises/GraphExercise';
import GraphInput from './Exercises/GraphInput';
//import AxisParent from './Exercises/AxisParent';
import UnitCircleExercise from './Exercises/UnitCircleExercise';
import UnitCircleInput from './Exercises/UnitCircleInput';
import UnitCircleParent from './Exercises/UnitCircleParent';

('./Exercises/AxisExercise');

interface ExerciseSideProps {
Expand All @@ -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;
Expand All @@ -39,20 +44,20 @@ ExerciseSideProps): JSX.Element {
setDisplayExercise(ExercisesNum);
}

if (exercises[displayExercise] == 'graph') {
if (exercises[displayExercise] == 'graph0') {
curExercise = (
<div>
<div>
<GraphExercise
origin={{ x: 0, y: 0 }}
points={[
{ x: -1, y: 1, label: 'A' },
{ x: 2, y: -1, label: 'B', line: 1 },
{ x: 1, y: 0, label: 'C', line: 0 },
{ x: 0, y: -2, label: 'D', line: 0 },
{ x: 0, y: 0, label: '' },
{ x: 2, y: 1, label: 'A', line: 1 },
{ x: 1, y: -1, label: 'B', line: 1 },
{ x: 0, y: -1, label: 'C', line: 1 },
]}
pointerPosition={{ x: 1, y: 1 }}
pointerOrientation={45}
pointerPosition={{ x: 0, y: 0 }}
pointerOrientation={0}
/>
</div>
<div style={{ paddingTop: '10vw' }}>
Expand All @@ -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: ')' },
],
},
Expand Down Expand Up @@ -121,6 +126,69 @@ ExerciseSideProps): JSX.Element {
/>
</div>
);*/
} else if (exercises[displayExercise] == 'graph1') {
curExercise = (
<div>
<div>
<GraphExercise
origin={{ x: 0, y: 0 }}
points={[
{ x: -1, y: 1, label: 'A' },
{ x: 2, y: -1, label: 'B', line: 1 },
{ x: 1, y: 0, label: 'C', line: 0 },
{ x: 0, y: -2, label: 'D', line: 0 },
]}
pointerPosition={{ x: 1, y: 1 }}
pointerOrientation={45}
/>
</div>
<div style={{ paddingTop: '10vw' }}>
<GraphInput
questionArray={[
{
textArray: [
{
type: 'text',
text: '# Goto point A and draw on the dotted line',
},
],
},
{
textArray: [
{ type: 'text', text: 'turtle.goto(' },
{ type: 'input', width: 2 },
{ type: 'text', text: ', -1)' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.setheading(' },
{ type: 'input', width: 4 },
{ type: 'text', text: ')' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.' },
{ type: 'input', width: 8 },
{ type: 'text', text: '()' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.goto(' },
{ type: 'input', width: 2 },
{ type: 'text', text: ', ' },
{ type: 'input', width: 2 },
{ type: 'text', text: ')' },
],
},
]}
nextExercise={() => incrementExercise()}
/>
</div>
</div>
);
} else if (exercises[displayExercise] == 'axis') {
curExercise = (
<div className="exercise-box">
Expand Down Expand Up @@ -148,21 +216,27 @@ ExerciseSideProps): JSX.Element {
curExercise = (
<div>
<div>
<UnitCircleExercise
turtleAngle={1}
markers={['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0']}
labels={['A', 'C', '', 'B', '']}
/>
<UnitCircleInput
nextExercise={() => {
// console.log('unit');
<UnitCircleParent
unitCircleMarkers={[
['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0'],
['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0'],
['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0'],
]}
unitCircleLabels={[
['A', 'C', '', 'B', ''],
['B', 'A', '', 'C', ''],
['', '', 'C', 'A', 'B'],
]}
directions={[
['left', 'right', '', 'right', ''],
['left', 'left', '', 'left', ''],
['', '', 'right', 'right', 'left'],
]}
toNextExercise={() => {
setDisplayExercise(displayExercise + 1);
incrementExercise();
return;
}}
markers={[['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0']]}
labels={[['A', 'C', '', 'B', '']]}
directions={[['left', 'right', '', 'right', '']]}
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/Exercises/GraphExercise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
123 changes: 85 additions & 38 deletions src/components/shared/Exercises/GraphInput.tsx
Original file line number Diff line number Diff line change
@@ -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 <p id="graphinput-check-question">{text}</p>;
interface GraphLineData {
textArray: GraphQuestionData[];
}

function GraphStringElement({
questionData,
setCorrect,
}: GraphQuestionGrouping) {
if (questionData.type == 'text') {
return <p id="graphinput-check-question">{questionData?.text ?? ''}</p>;
} 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 (
<input
type="text"
className="graphinput-check-box"
style={{ width: `${width * 16}px` }}
/>
<div>
<input
type="text"
className="graphinput-check-box"
style={{ width: `${(questionData?.width ?? 3) * 16}px` }}
onChange={handleChange}
/>
</div>
);
}
}

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 (
<GraphStringElement
type={elementData?.type}
text={elementData?.text}
width={elementData?.width}
answer={elementData?.answer}
/>
<GraphStringElement questionData={elementData} setCorrect={setCorrect} />
);
};
return (
<div id={'graphinput-question-container'}>{textArray.map(makeElement)}</div>
<div id={'graphinput-question-container'}>
{data.textArray.map(makeElement)}
</div>
);
/*return (
<div id="graphinput-question-container">
Expand All @@ -58,36 +85,56 @@ function GraphInput({
questionArray,
nextExercise,
}: GraphInputProps): JSX.Element {
const makeLine = (lineArray: GraphQuestion): JSX.Element => {
return <GraphLine textArray={lineArray.textArray} />;
const valueMap = new Map<number, boolean>();
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 <GraphLine data={data} setCorrect={setCorrect} />;
};
return (
<div id="graphinput-container">
<div id="graphinput-question">
Fill in the blanks to move the cursor along the path!
</div>
<div id="graphinput-check-question"></div>
<div id="graphinput-question-box">{questionArray.map(makeLine)}</div>
<div id="graphinput-question-box">
{questionArray.map((x) => makeLine(x, setValueCorrect))}
</div>
<div id="graphinput-check-button-container">
<button id="graphinput-check-button" onClick={nextExercise}>
<button id="graphinput-check-button" onClick={checkCorrect}>
Check
</button>
</div>
</div>
);
/*
return (
<div id="graphinput-container">
<div id="graphinput-question-box">
<GraphLine
textArray={[
{ text: 'Hi!', type: 'text' },
{ type: 'input', width: 10 },
]}
/>
</div>
</div>
);*/
}

export default GraphInput;
2 changes: 1 addition & 1 deletion src/components/shared/Exercises/UnitCircleExercise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function UnitCircleExercise({
curAngle += angleBetweenTicks;
cursorAngle += cursorTicks;
return (
<div key={element}>
<div key={idx}>
<div
className="circle-exercise"
style={{
Expand Down
Loading

0 comments on commit 0f03682

Please sign in to comment.