Skip to content
Snippets Groups Projects
Commit 1fd76927 authored by chris's avatar chris
Browse files

handleChange

parent 07e8f379
No related branches found
No related tags found
1 merge request!348Multiple single
......@@ -33,29 +33,31 @@ const CustomSwitch = ({ node, getPos }) => {
const handleChange = () => {
setChecked(!checked);
main.state.doc.descendants((editorNode, pos) => {
if (editorNode.type.name === 'multiple_choice_single_correct_container') {
editorNode.content.content.forEach(element => {
if (element.attrs.id === node.attrs.id) {
main.dispatch(
main.state.tr.setNodeMarkup(getPos(), undefined, {
...element.attrs,
correct: !checked,
}),
);
} else if (element.attrs.correct) {
// console.log(element);
// main.dispatch(
// main.state.tr.setNodeMarkup(getPos() + 4, undefined, {
// ...element.attrs,
// correct: false,
// }),
// );
const { tr } = main.state;
main.state.doc.descendants((parentNode, parentPos) => {
if (parentNode.type.name === 'multiple_choice_single_correct_container') {
parentNode.descendants((element, position) => {
if (
element.type.name === 'multiple_choice_single_correct' &&
element.attrs.id === node.attrs.id
) {
tr.setNodeMarkup(getPos(), undefined, {
...element.attrs,
correct: !checked,
});
} else if (
element.type.name === 'multiple_choice_single_correct' &&
element.attrs.correct
) {
tr.setNodeMarkup(parentPos + position + 1, undefined, {
...element.attrs,
correct: false,
});
}
});
}
});
main.dispatch(tr);
};
return (
......
import { v4 as uuidv4 } from 'uuid';
const multipleChoiceSingleCorrectContainerNode = {
attrs: {
id: { default: '' },
id: { default: uuidv4() },
class: { default: 'multiple-choice-single-correct' },
correctId: { default: '' },
},
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment