Skip to content

Commit

Permalink
update handle remove function
Browse files Browse the repository at this point in the history
  • Loading branch information
anakaren-rojas committed Dec 20, 2024
1 parent e6e8708 commit 1577d98
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/perseus-editor/src/widgets/expression-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ExpressionEditor extends React.Component<Props, State> {
};

_newEmptyAnswerForm: () => any = () => {
const newKey = _makeNewKey(this.props.answerForms)
const newKey = _makeNewKey(this.props.answerForms);
return {
considered: "correct",
form: false,
Expand All @@ -212,8 +212,11 @@ class ExpressionEditor extends React.Component<Props, State> {
handleRemoveForm: (answerKey: number) => void = (i) => {
const answerForms = this.props.answerForms.slice();
answerForms.splice(i, 1);

this.change({answerForms});
const updatedAnswerForms = answerForms.map((form, index) => ({
...form,
key: `${index}`,
}));
this.change({answerForms: updatedAnswerForms});
};

// This function is designed to update the answerForm property
Expand Down Expand Up @@ -346,7 +349,7 @@ class ExpressionEditor extends React.Component<Props, State> {

render(): React.ReactNode {
const answerOptions: React.JSX.Element[] = this.props.answerForms.map(
(ans: AnswerForm) => {
(ans: AnswerForm, index: number) => {
const key = parseAnswerKey(ans);

const expressionProps: Partial<
Expand Down Expand Up @@ -378,7 +381,7 @@ class ExpressionEditor extends React.Component<Props, State> {
expressionProps={expressionProps}
form={ans.form}
simplify={ans.simplify}
onDelete={() => this.handleRemoveForm(key)}
onDelete={() => this.handleRemoveForm(index)}
onChangeSimplify={(simplify) =>
this.changeSimplify(key, simplify)
}
Expand Down Expand Up @@ -567,6 +570,7 @@ class AnswerOption extends React.Component<

handleImSure = () => {
this.props.onDelete();
this.handleCancelDelete();
};

handleCancelDelete = () => {
Expand Down

0 comments on commit 1577d98

Please sign in to comment.