Skip to content

Commit

Permalink
Ensured that FinishCode properly accesses (#271)
Browse files Browse the repository at this point in the history
the DropDown values without causing issues in checkmark disabling.
  • Loading branch information
RahulKhanna14 authored Feb 28, 2024
1 parent 26a3fa2 commit 8c47de5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/components/binary-comps/BinaryCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function BinaryCode(): JSX.Element {
handleUpdateAnswer(0, chosenAnswer)
}
name="binary-drop001"
finish={true}
/>
</>
</Tab>
Expand All @@ -168,6 +169,7 @@ function BinaryCode(): JSX.Element {
handleUpdateAnswer(1, chosenAnswer)
}
name="binary-drop3"
finish={true}
/>
</>
</Tab>
Expand All @@ -187,6 +189,7 @@ function BinaryCode(): JSX.Element {
handleUpdateAnswer(2, chosenAnswer)
}
name="binary-drop4"
finish={true}
/>
{')'}
</>
Expand All @@ -207,6 +210,7 @@ function BinaryCode(): JSX.Element {
handleUpdateAnswer(3, chosenAnswer)
}
name="binary-drop5"
finish={true}
/>
{')'}
</>
Expand Down
4 changes: 2 additions & 2 deletions src/components/binary-comps/BinarySearchExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export default function BinarySearchExample({
<br />
<div>
{' '}
Is the currently highlighted word alphabetically before or after{' '}
{answer}?{' '}
Does the target word {answer} appear alphabetically before or after the
currently highlighted word?
</div>
<div
style={{
Expand Down
3 changes: 3 additions & 0 deletions src/components/bunny-comps/BunnyCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function BunnyCode(): JSX.Element {
handleUpdateAnswer(0, chosenAnswer)
}
name="bunny-drop2"
finish={true}
/>
<br />
<Tab>
Expand All @@ -173,6 +174,7 @@ function BunnyCode(): JSX.Element {
handleUpdateAnswer(1, chosenAnswer)
}
name="bunny-drop3"
finish={true}
/>
</>
</Tab>
Expand All @@ -186,6 +188,7 @@ function BunnyCode(): JSX.Element {
handleUpdateAnswer(2, chosenAnswer)
}
name="bunny-drop4"
finish={true}
/>
</>
</Tab>
Expand Down
4 changes: 4 additions & 0 deletions src/components/dining-comps/DiningCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ function DiningCode(): JSX.Element {
handleUpdateAnswer(0, chosenAnswer)
}
name="dining-drop1"
finish={true}
/>
</>
</Tab>
Expand All @@ -176,6 +177,7 @@ function DiningCode(): JSX.Element {
handleUpdateAnswer(1, chosenAnswer)
}
name="dining-drop2"
finish={true}
/>
)
<br />
Expand All @@ -189,6 +191,7 @@ function DiningCode(): JSX.Element {
handleUpdateAnswer(2, chosenAnswer)
}
name="dining-drop3"
finish={true}
/>
)
<br />
Expand All @@ -202,6 +205,7 @@ function DiningCode(): JSX.Element {
handleUpdateAnswer(3, chosenAnswer)
}
name="dining-drop4"
finish={true}
/>
</>
</Tab>
Expand Down
2 changes: 2 additions & 0 deletions src/components/intro_comps/intro_code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function IntroCode(): JSX.Element {
}
size="medium"
name="intro-drop1"
finish={true}
/>
:
<br />
Expand All @@ -122,6 +123,7 @@ function IntroCode(): JSX.Element {
}
size="small"
name="intro-drop2"
finish={true}
/>
</>
</Tab>
Expand Down
4 changes: 4 additions & 0 deletions src/components/mario-comps/MarioCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ function MarioCode(): JSX.Element {
handleUpdateAnswer(0, chosenAnswer)
}
name="mario-drop2"
finish={true}
/>{' '}
:
<Tab>
Expand All @@ -601,6 +602,7 @@ function MarioCode(): JSX.Element {
handleUpdateAnswer(1, chosenAnswer)
}
name="mario-drop3"
finish={true}
/>
</>
</Tab>
Expand All @@ -614,6 +616,7 @@ function MarioCode(): JSX.Element {
handleUpdateAnswer(2, chosenAnswer)
}
name="mario-drop4"
finish={true}
/>
+ <Gold>recurSum</Gold>(
<MarioDropdown
Expand All @@ -625,6 +628,7 @@ function MarioCode(): JSX.Element {
handleUpdateAnswer(3, chosenAnswer)
}
name="mario-drop5"
finish={true}
/>
)
</>
Expand Down
40 changes: 25 additions & 15 deletions src/components/shared/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface DropdownProps {
answer: string;
update_answer: any;
name: string;
finish?: boolean;
}

function Dropdown(props: DropdownProps): JSX.Element {
Expand Down Expand Up @@ -47,27 +48,36 @@ function Dropdown(props: DropdownProps): JSX.Element {
const handleChange = (selectedOption: any) => {
const chosenAnswer = selectedOption.value;

if (correctAnswers === undefined) {
if (
(props.finish && props.correct_answer === undefined) ||
(!props.finish && correctAnswers === undefined)
) {
// Code the Components Together dropdown
props.update_answer(chosenAnswer);
} else {
// KhanCard dropdown
if (props.finish) {
const newArray2 = props.correct_answer.map((val, i) => {
if (i == props.index) return props.answer === chosenAnswer;
else return val;
});
props.update_answer(newArray2);
} else {
const newArray = correctAnswers.map((val, i) => {
if (chosenAnswer === '' || chosenAnswer === null) {
//return null;
return false;
}

const newArray = correctAnswers.map((val, i) => {
if (chosenAnswer === '' || chosenAnswer === null) {
return null;
}

if (i == props.index) {
return props.answer === chosenAnswer;
} else {
return val;
}
});

setCorrectAnswers(newArray);
if (i == props.index) {
return props.answer === chosenAnswer;
} else {
return val;
}
});
setCorrectAnswers(newArray);
}
}

setSelectedValue(chosenAnswer);
};

Expand Down

0 comments on commit 8c47de5

Please sign in to comment.