From 697c2bd76fc6c6c7cfe78b4a5d4d84f23b884d8c Mon Sep 17 00:00:00 2001 From: brynnchernosky <56202540+brynnchernosky@users.noreply.github.com> Date: Sat, 6 May 2023 15:23:50 -0400 Subject: refactor answer inputs --- .../nodes/PhysicsBox/PhysicsSimulationBox.tsx | 332 +++++++++------------ .../PhysicsBox/PhysicsSimulationInputField.tsx | 1 - 2 files changed, 139 insertions(+), 194 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx index 695b0733d..340004cef 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx @@ -145,10 +145,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent; // this.dataDoc.currentForceSketch = this.dataDoc.currentForceSketch ?? null; // this.dataDoc.deleteMode = this.dataDoc.deleteMode ?? false; // this.dataDoc.forceSketches = this.dataDoc.forceSketches ?? []; + this.dataDoc.answers = []; this.dataDoc.hintDialogueOpen = this.dataDoc.hintDialogueOpen ?? false; this.dataDoc.noMovement = this.dataDoc.noMovement ?? false; this.dataDoc.questionNumber = this.dataDoc.questionNumber ?? 0; @@ -285,7 +285,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent); }; // In review mode, reset problem variables and generate a new question @@ -824,195 +823,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { - let answerInput = []; - const d = new Date(); - for (let i = 0; i < question.answerParts.length; i++) { - if (question.answerParts[i] == "force of gravity") { - this.dataDoc.reviewGravityMagnitude = (0); - answerInput.push( -
- Gravity magnitude

} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewGravityMagnitude'} - step={0.1} - unit={"N"} - upperBound={50} - value={this.dataDoc.reviewGravityMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> -
- ); - } else if (question.answerParts[i] == "angle of gravity") { - this.dataDoc.reviewGravityAngle = (0); - answerInput.push( -
- Gravity angle

} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewGravityAngle'} - step={1} - unit={"°"} - upperBound={360} - value={this.dataDoc.reviewGravityAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> -
- ); - } else if (question.answerParts[i] == "normal force") { - this.dataDoc.reviewNormalMagnitude = (0); - answerInput.push( -
- Normal force magnitude

} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewNormalMagnitude'} - step={0.1} - unit={"N"} - upperBound={50} - value={this.dataDoc.reviewNormalMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> -
- ); - } else if (question.answerParts[i] == "angle of normal force") { - this.dataDoc.reviewNormalAngle = (0); - answerInput.push( -
- Normal force angle

} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewNormalAngle'} - step={1} - unit={"°"} - upperBound={360} - value={this.dataDoc.reviewNormalAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> -
- ); - } else if (question.answerParts[i] == "force of static friction") { - this.dataDoc.reviewStaticMagnitude = (0); - answerInput.push( -
- Static friction magnitude

} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewStaticMagnitude'} - step={0.1} - unit={"N"} - upperBound={50} - value={this.dataDoc.reviewStaticMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> -
- ); - } else if (question.answerParts[i] == "angle of static friction") { - this.dataDoc.reviewStaticAngle = (0); - answerInput.push( -
- Static friction angle

} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewStaticAngle'} - step={1} - unit={"°"} - upperBound={360} - value={this.dataDoc.reviewStaticAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> -
- ); - } else if (question.answerParts[i] == "coefficient of static friction") { - this.updateReviewForcesBasedOnCoefficient(0); - answerInput.push( -
- - μs - - } - lowerBound={0} - dataDoc={this.dataDoc} - prop={'coefficientOfStaticFriction'} - step={0.1} - unit={""} - upperBound={1} - value={this.dataDoc.coefficientOfStaticFriction} - effect={this.updateReviewForcesBasedOnCoefficient} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } else if (question.answerParts[i] == "wedge angle") { - this.updateReviewForcesBasedOnAngle(0); - answerInput.push( -
- θ} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'wedgeAngle'} - step={1} - unit={"°"} - upperBound={49} - value={this.dataDoc.wedgeAngle ?? 26} - effect={(val: number) => { - this.changeWedgeBasedOnNewAngle(val); - this.updateReviewForcesBasedOnAngle(val); - }} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } - } - - this.dataDoc.answerInputFields = ( -
- {answerInput} -
- ); - }; - // Default setup for uniform circular motion simulation setupCircular = (value: number) => { this.dataDoc.showComponentForces = (false); @@ -1459,6 +1273,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent

{this.dataDoc.simulationType} review problems in progress!

+
)} {this.dataDoc.mode == "Review" && this.dataDoc.simulationType == "Inclined Plane" && ( @@ -1517,9 +1332,140 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent{this.dataDoc.questionPartOne}

{this.dataDoc.questionPartTwo}

-
{this.dataDoc.answerInputFields}
- - +
+ {this.dataDoc.selectedQuestion.answerParts.includes("force of gravity") && + (Gravity magnitude

} + lowerBound={0} + dataDoc={this.dataDoc} + prop={'reviewGravityMagnitude'} + step={0.1} + unit={"N"} + upperBound={50} + value={this.dataDoc.reviewGravityMagnitude} + showIcon={false} + correctValue={this.dataDoc.answers[this.dataDoc.selectedQuestion.answerParts.indexOf("force of gravity")]} + labelWidth={"7em"} + />) + } + {this.dataDoc.selectedQuestion.answerParts.includes("angle of gravity") && ( + Gravity angle

} + lowerBound={0} + dataDoc={this.dataDoc} + prop={'reviewGravityAngle'} + step={1} + unit={"°"} + upperBound={360} + value={this.dataDoc.reviewGravityAngle} + radianEquivalent={true} + showIcon={false} + correctValue={this.dataDoc.answers[this.dataDoc.selectedQuestion.answerParts.indexOf("angle of gravity")]} + labelWidth={"7em"} + /> + )} + {this.dataDoc.selectedQuestion.answerParts.includes("normal force") && ( + Normal force magnitude

} + lowerBound={0} + dataDoc={this.dataDoc} + prop={'reviewNormalMagnitude'} + step={0.1} + unit={"N"} + upperBound={50} + value={this.dataDoc.reviewNormalMagnitude} + showIcon={false} + correctValue={this.dataDoc.answers[this.dataDoc.selectedQuestion.answerParts.indexOf("normal force")]} + labelWidth={"7em"} + /> + )} + {this.dataDoc.selectedQuestion.answerParts.includes("angle of normal force") && ( + Normal force angle

} + lowerBound={0} + dataDoc={this.dataDoc} + prop={'reviewNormalAngle'} + step={1} + unit={"°"} + upperBound={360} + value={this.dataDoc.reviewNormalAngle} + radianEquivalent={true} + showIcon={false} + correctValue={this.dataDoc.answers[this.dataDoc.selectedQuestion.answerParts.indexOf("angle of normal force")]} + labelWidth={"7em"} + /> + )} + {this.dataDoc.selectedQuestion.answerParts.includes("force of static friction") && ( + Static friction magnitude

} + lowerBound={0} + dataDoc={this.dataDoc} + prop={'reviewStaticMagnitude'} + step={0.1} + unit={"N"} + upperBound={50} + value={this.dataDoc.reviewStaticMagnitude} + showIcon={false} + correctValue={this.dataDoc.answers[this.dataDoc.selectedQuestion.answerParts.indexOf("force of static friction")]} + labelWidth={"7em"} + /> + )} + {this.dataDoc.selectedQuestion.answerParts.includes("angle of static friction") && ( + Static friction angle

} + lowerBound={0} + dataDoc={this.dataDoc} + prop={'reviewStaticAngle'} + step={1} + unit={"°"} + upperBound={360} + value={this.dataDoc.reviewStaticAngle} + radianEquivalent={true} + showIcon={false} + correctValue={this.dataDoc.answers[this.dataDoc.selectedQuestion.answerParts.indexOf("angle of static friction")]} + labelWidth={"7em"} + /> + )} + {this.dataDoc.selectedQuestion.answerParts.includes("coefficient of static friction") && ( + + μs + + } + lowerBound={0} + dataDoc={this.dataDoc} + prop={'coefficientOfStaticFriction'} + step={0.1} + unit={""} + upperBound={1} + value={this.dataDoc.coefficientOfStaticFriction} + effect={this.updateReviewForcesBasedOnCoefficient} + showIcon={false} + correctValue={this.dataDoc.answers[this.dataDoc.selectedQuestion.answerParts.indexOf("coefficient of static friction")]} + /> + )} + {this.dataDoc.selectedQuestion.answerParts.includes("wedge angle") && ( + θ} + lowerBound={0} + dataDoc={this.dataDoc} + prop={'wedgeAngle'} + step={1} + unit={"°"} + upperBound={49} + value={this.dataDoc.wedgeAngle ?? 26} + effect={(val: number) => { + this.changeWedgeBasedOnNewAngle(val); + this.updateReviewForcesBasedOnAngle(val); + }} + radianEquivalent={true} + showIcon={false} + correctValue={this.dataDoc.answers[this.dataDoc.selectedQuestion.answerParts.indexOf("wedge angle")]} + /> + )} +
+ )} {this.dataDoc.mode == "Tutorial" && (
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx index 353b386a6..5e5a60edd 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx @@ -50,7 +50,6 @@ export default class InputField extends React.Component { if (prevProps.value != this.props.value && !isNaN(this.props.value)) { if (this.props.mode == "Freeform") { if (Math.abs(this.state.tempValue - Number(this.props.value)) > 1) { - console.log('update temp value', Number(this.props.value)) this.setState({tempValue: Number(this.props.value)}) } } -- cgit v1.2.3-70-g09d2