Skip to content

Commit

Permalink
#4826 fix for missing word
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanromakh committed Feb 22, 2023
1 parent be8004d commit 264b562
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 8 deletions.
70 changes: 66 additions & 4 deletions src/components/play/questionTypes/missingWord/MissingWord.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
color: var(--theme-dark-blue);
font-size: 1.25vw;

> div {
font-size: 0;
}

div {
display: inline;
}
Expand All @@ -38,10 +42,6 @@
font-family: $font-family-regular;
font-size: 1.25vw;
color: var(--theme-dark-blue);

.MuiSelect-root {
line-height: 1;
}
}

.question-hint.correct {
Expand Down Expand Up @@ -91,4 +91,66 @@
.MuiListItem-root {
color: var(--theme-dark-blue) !important;
font-family: $font-family-regular !important;
}

.play-preview-pages .sorted-row .brick-row-container
.brick-container .introduction-page .missing-word-choice {
.MuiSelect-icon {
top: unset !important;
right: -0.4vw;
bottom: -0.3vw;
}

.MuiSelect-selectMenu {
padding-left: 0;
padding-right: 0;
height: 1.8vw;
}

.MuiInput-underline:before,
.MuiInput-underline:after {
bottom: -0.5vw;
}

.MuiSelect-root {
position: absolute;
bottom: -0.5vw;
}

.missing-select {
&.correct {
.MuiSelect-root {
padding-left: 0.5vw !important;
background: var(--theme-green);
}

svg {
display: none;
}
&.Mui-disabled:before {
border-bottom-style: none !important;
}
}

&.wrong {
.MuiSelect-root {
padding-left: 0.2vw;
padding-right: 0.2vw;
background: var(--theme-orange);
}
svg {
color: var(--white);
}
&.MuiInput-underline:before {
content: none;
border-bottom: none !important;
}

color: var(--white);

p {
color: var(--white);
}
}
}
}
23 changes: 19 additions & 4 deletions src/components/play/questionTypes/missingWord/MissingWord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface MissingComponent {

interface MissingAttemptAnswer {
value: number | string;
updated?: boolean;
}

interface MissingWordProps extends CompQuestionProps {
Expand Down Expand Up @@ -49,7 +50,10 @@ class MissingWord extends CompComponent<MissingWordProps, MissingWordState> {
if (props.answers && props.answers.length > 0) {
userAnswers = props.answers;
} else if (props.attempt?.answer?.length > 0) {
props.attempt.answer.forEach(a => userAnswers.push(a));
props.attempt.answer.forEach(a => {
a.updated = false;
userAnswers.push(a);
});
} else {
props.component.choices.forEach(() => userAnswers.push({ value: -1 }));
}
Expand Down Expand Up @@ -80,8 +84,11 @@ class MissingWord extends CompComponent<MissingWordProps, MissingWordState> {

setUserAnswer(e: any, index: number) {
let userAnswers = this.state.userAnswers;
userAnswers[index].value = e.target.value as number;
let userAnswer = userAnswers[index];
userAnswer.value = e.target.value as number;
userAnswer.updated = true;
this.setState({ userAnswers });

if (this.props.onAttempted) {
this.props.onAttempted();
}
Expand Down Expand Up @@ -115,7 +122,7 @@ class MissingWord extends CompComponent<MissingWordProps, MissingWordState> {
if (!this.state.userAnswers[index]) {
return <PageLoader content="...Loading..." />;
}
let { value } = this.state.userAnswers[index];
let { value, updated } = this.state.userAnswers[index];
if (value === -1) value = '';


Expand All @@ -124,10 +131,18 @@ class MissingWord extends CompComponent<MissingWordProps, MissingWordState> {
disabled = this.isAnswerCorrect(index);
}

const isCorrect = disabled;
let isWrong = false;
if (this.props.isReview && (this.props.attempt === this.props.liveAttempt || (this.props.liveAttempt && this.props.liveAttempt.correct === true))) {
if (!updated) {
isWrong = !isCorrect;
}
}

return (
<Select
disabled={disabled}
className="missing-select"
className={`missing-select ${isCorrect ? 'correct' : ''} ${isWrong ? 'wrong' : ''}`}
value={value}
IconComponent={ExpandMoreIcon}
onChange={e => this.setUserAnswer(e, index)}
Expand Down

0 comments on commit 264b562

Please sign in to comment.