Skip to content

Commit

Permalink
Equation Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyabhandari0220 committed Dec 8, 2023
1 parent fde1ae1 commit 73c3c9c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 26 deletions.
78 changes: 72 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"http2": "~3.3.7",
"list-react-files": "~0.2.0",
"localforage": "~1.10.0",
"mathlive": "^0.95.5",
"random-seed": "~0.3.0",
"react": "~16.14.0",
"react-cursor-position": "~3.0.3",
Expand Down Expand Up @@ -64,5 +65,5 @@
"react-app-rewire-alias": "~1.1.7",
"react-app-rewired": "~2.2.1"
},
"homepage": "place-holder"
"homepage": "OATutor-EquationEditor"
}
53 changes: 36 additions & 17 deletions src/components/problem-input/ProblemInput.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { createRef } from "react";
import Grid from "@material-ui/core/Grid";
import EquationEditor from "equation-editor-react";
import TextField from "@material-ui/core/TextField";
import MultipleChoice from "./MultipleChoice";
import GridInput from "./GridInput";
import MatrixInput from "./MatrixInput";
import { renderText } from "../../platform-logic/renderText";
import clsx from "clsx";
import "mathlive";
import './ProblemInput.css'
import { shuffleArray } from "../../util/shuffleArray";
import { EQUATION_EDITOR_AUTO_COMMANDS, EQUATION_EDITOR_AUTO_OPERATORS, ThemeContext } from "../../config/config";
Expand All @@ -22,6 +22,10 @@ class ProblemInput extends React.Component {
this.equationRef = createRef()

this.onEquationChange = this.onEquationChange.bind(this)

this.state = {
value: "",
};
}

componentDidMount() {
Expand Down Expand Up @@ -80,6 +84,8 @@ class ProblemInput extends React.Component {
const { classes, state, index, showCorrectness, allowRetry, variabilization } = this.props;
const { use_expanded_view, debug } = this.context;
let { problemType, stepAnswer, hintAnswer, units } = this.props.step;
const keepMCOrder = this.props.keepMCOrder;
const keyboardType = this.props.keyboardType;

const problemAttempted = state.isCorrect != null
const correctAnswer = Array.isArray(stepAnswer) ? stepAnswer[0] : hintAnswer[0]
Expand All @@ -88,28 +94,30 @@ class ProblemInput extends React.Component {
if (this.isMatrixInput()) {
problemType = "MatrixInput"
}

try {
window.mathVirtualKeyboard.layouts = [keyboardType];
} catch {
window.mathVirtualKeyboard.layouts = ["default"];
}


return (
<Grid container spacing={0} justifyContent="center" alignItems="center"
className={clsx(disableInput && 'disable-interactions')}>
<Grid item xs={1} md={problemType === "TextBox" ? 4 : false}/>
<Grid item xs={9} md={problemType === "TextBox" ? 3 : 12}>
{(problemType === "TextBox" && this.props.step.answerType !== "string") && (
<center
ref={this.equationRef}
className={clsx(showCorrectness && state.isCorrect === false && classes.textBoxLatexIncorrect, state.usedHints && classes.textBoxLatexUsedHint, classes.textBoxLatex)}
{...stagingProp({
"data-selenium-target": `arithmetic-answer-${index}`
})}
<math-field
onInput={evt => this.props.setInputValState(evt.target.value)}
style={{"display": "block"}}
value={(use_expanded_view && debug) ? correctAnswer : state.inputVal}
onChange={this.onEquationChange}
autoCommands={EQUATION_EDITOR_AUTO_COMMANDS}
autoOperatorNames={EQUATION_EDITOR_AUTO_OPERATORS}
>
<EquationEditor
value={(use_expanded_view && debug) ? correctAnswer : state.inputVal}
onChange={this.onEquationChange}
style={{ width: "100%" }}
autoCommands={EQUATION_EDITOR_AUTO_COMMANDS}
autoOperatorNames={EQUATION_EDITOR_AUTO_OPERATORS}
/>
</center>
</math-field>

)}
{(problemType === "TextBox" && this.props.step.answerType === "string") && (
<TextField
Expand Down Expand Up @@ -146,7 +154,18 @@ class ProblemInput extends React.Component {
>
</textarea>
)}
{problemType === "MultipleChoice" && (
{(problemType === "MultipleChoice" && keepMCOrder) && (
<MultipleChoice
onChange={(evt) => this.props.editInput(evt)}
choices={[...this.props.step.choices].reverse()}
index={index}
{...(use_expanded_view && debug) ? {
defaultValue: correctAnswer
} : {}}
variabilization={variabilization}
/>
)}
{(problemType === "MultipleChoice" && (keepMCOrder === false || keepMCOrder === null)) && (
<MultipleChoice
onChange={(evt) => this.props.editInput(evt)}
choices={shuffleArray(this.props.step.choices, this.props.seed)}
Expand Down Expand Up @@ -195,4 +214,4 @@ class ProblemInput extends React.Component {
}
}

export default ProblemInput
export default ProblemInput
6 changes: 6 additions & 0 deletions src/components/problem-layout/Problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ class Problem extends React.Component {

const giveStuFeedback = this.props.lesson?.giveStuFeedback;
const giveStuHints = this.props.lesson?.giveStuHints;
const keepMCOrder = this.props.lesson?.keepMCOrder;
const keyboardType = this.props.lesson?.keyboardType;
const doMasteryUpdate = this.props.lesson?.doMasteryUpdate;
const unlockFirstHint = this.props.lesson?.unlockFirstHint;
const giveStuBottomHint = this.props.lesson?.allowBottomHint;

this.giveHintOnIncorrect = true;
this.giveStuFeedback = giveStuFeedback == null || giveStuFeedback;
this.keepMCOrder = keepMCOrder != null && keepMCOrder;
this.keyboardType = keyboardType != null && keyboardType;
this.giveStuHints = giveStuHints == null || giveStuHints;
this.doMasteryUpdate = doMasteryUpdate == null || doMasteryUpdate;
this.unlockFirstHint = unlockFirstHint != null && unlockFirstHint;
Expand Down Expand Up @@ -462,6 +466,8 @@ class Problem extends React.Component {
problemSubTitle={problem.body}
giveStuFeedback={this.giveStuFeedback}
giveStuHints={this.giveStuHints}
keepMCOrder={this.keepMCOrder}
keyboardType={this.keyboardType}
giveHintOnIncorrect={
this.giveHintOnIncorrect
}
Expand Down
7 changes: 5 additions & 2 deletions src/components/problem-layout/ProblemCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class ProblemCard extends React.Component {
this.giveStuHints = props.giveStuHints;
this.unlockFirstHint = props.unlockFirstHint;
this.giveHintOnIncorrect = props.giveHintOnIncorrect

this.keepMCOrder = props.keepMCOrder;
this.keyboardType = props.keyboardType;
this.allowRetry = this.giveStuFeedback;

this.giveStuBottomHint = props.giveStuBottomHint;
Expand Down Expand Up @@ -589,6 +590,8 @@ class ProblemCard extends React.Component {
state={this.state}
step={this.step}
seed={this.props.seed}
keepMCOrder={this.props.keepMCOrder}
keyboardType={this.props.keyboardType}
_setState={(state) => this.setState(state)}
context={this.context}
editInput={this.editInput}
Expand Down Expand Up @@ -731,4 +734,4 @@ class ProblemCard extends React.Component {
}
}

export default withStyles(styles)(ProblemCard);
export default withStyles(styles)(ProblemCard);

0 comments on commit 73c3c9c

Please sign in to comment.