Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1671 from benetech/frontend_v2
Browse files Browse the repository at this point in the history
#1634 - fix painterro usage
  • Loading branch information
rupeshparab authored Feb 5, 2021
2 parents 70f1880 + 4f8c5c4 commit bab36fe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/components/Editor/components/MyWork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class MyWork extends Component {
}

componentDidMount() {
document.getElementById('mathEditorActive').addEventListener('keydown', this.HandleKeyDown);
const { problem } = this.props;
const { scratchpadMode } = problem.work;
if (scratchpadMode) {
setTimeout(this.openScratchpad, 0);
}
this.bindingHelper();
}

bindingHelper = () => {
if (this.props.bindDisplayFunction) {
this.props.bindDisplayFunction((scratchpadContent) => {
this.props.updateWork({
Expand All @@ -49,12 +59,6 @@ class MyWork extends Component {
this.displayScratchpadImage();
});
}
document.getElementById('mathEditorActive').addEventListener('keydown', this.HandleKeyDown);
const { problem } = this.props;
const { scratchpadMode } = problem.work;
if (scratchpadMode) {
setTimeout(this.openScratchpad, 0);
}
}

getScratchPadValue = () => {
Expand Down Expand Up @@ -204,9 +208,9 @@ class MyWork extends Component {

displayScratchpadImage() {
const { work } = this.props.problem;
if (work.scratchpadContent) {
if (work.scratchpadContent || work.isScratchpadUsed) {
this.clearAndResizeScratchPad(work.scratchpadContent);
setTimeout(() => {
this.clearAndResizeScratchPad(work.scratchpadContent);
this.scratchPadPainterro.show(work.scratchpadContent || '');
}, 500);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class Editor extends Component {
deleteStepsCallback={() => clearAll(this)}
updateCallback={img => updateStep(this, img)}
bindDisplayFunction={
f => this.props.updateProblemStore({ displayScratchpad: (f || (() => {})) })
f => this.props.updateProblemStore({ displayScratchpad: f })
}
showDelete={problemStore.actionsStack.length > 0}
newProblem={this.id === 'newEditor'}
Expand Down
5 changes: 4 additions & 1 deletion src/components/Editor/stepsOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ function editStep(context, stepNumber) {
const mathStep = problemStore.solution.steps[stepNumber - 1];
const updatedMathField = problemList.theActiveMathField;
updatedMathField.$latex(mathStep.stepValue);
problemStore.displayScratchpad(mathStep.scratchpad);
const solution = Object.assign({}, problemStore.solution);
const steps = problemStore.solution.steps.filter(step => !step.inProgress);
solution.steps = steps;
Expand All @@ -99,6 +98,9 @@ function editStep(context, stepNumber) {
isUpdated: true,
});
context.moveEditorBelowSpecificStep(stepNumber);
setTimeout(() => {
problemStore.displayScratchpad(mathStep.scratchpad);
}, 500);
}

function updateStep(context, img) {
Expand Down Expand Up @@ -130,6 +132,7 @@ function updateStep(context, img) {
const problemSteps = problemStore.solution.problem.steps.filter(step => !step.inProgress);
problemStore.solution.problem.steps = problemSteps;
}
problemStore.displayScratchpad();
updateProblemStore({
isUpdated: true,
solution,
Expand Down
11 changes: 10 additions & 1 deletion src/redux/problem/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const problem = (state = initialState, {
case 'RESET_PROBLEM':
return {
...initialState,
displayScratchpad: state.displayScratchpad,
work: {
...initialState.work,
scratchpadMode: state.work.scratchpadMode,
Expand Down Expand Up @@ -157,12 +158,18 @@ const problem = (state = initialState, {
}
case 'SET_EDIT_PROBLEM': {
let textAreaValue = initialState.textAreaValue;
let scratchpadContent = initialState.work.scratchpadContent;
if (payload.action === 'edit') {
textAreaValue = payload.textAreaValue;
scratchpadContent = payload.scratchpadContent;
}
return {
...state,
textAreaValue,
work: {
...state.work,
scratchpadContent,
},
};
}
case 'PROCESS_FETCHED_PROBLEM': {
Expand All @@ -182,6 +189,7 @@ const problem = (state = initialState, {
...state,
textAreaValue: initialState.textAreaValue,
stepsFromLastSave: initialState.stepsFromLastSave,
work: initialState.work,
solution: initialState.solution,
};
}
Expand All @@ -190,7 +198,8 @@ const problem = (state = initialState, {
if (payload.modals.includes('addProblems')) {
return {
...state,
textAreaValue: initialState.textAreaValue,
work: initialState.work,
scratchpadContent: initialState.scratchpadContent,
};
}
return state;
Expand Down

0 comments on commit bab36fe

Please sign in to comment.