Skip to content
Snippets Groups Projects
Commit 741f7f97 authored by chris's avatar chris
Browse files

update correct attr

parent 29e792d0
No related branches found
No related tags found
1 merge request!308Answer nodeview
......@@ -29,7 +29,7 @@ export default class MultipleChoiceNodeView extends AbstractNodeView {
)
return true;
if (!node.sameMarkup(this.node)) return false;
// if (!node.sameMarkup(this.node)) return false;
this.node = node;
if (this.context.view[node.attrs.id]) {
const { state } = this.context.view[node.attrs.id];
......
import React, { useState, useContext } from 'react';
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useState, useContext, useEffect } from 'react';
import { WaxContext } from 'wax-prosemirror-core';
import { DocumentHelpers } from 'wax-prosemirror-utilities';
import styled from 'styled-components';
import Switch from './Switch';
......@@ -24,6 +26,15 @@ const CustomSwitch = ({ node, getPos }) => {
const context = useContext(WaxContext);
const [checked, setChecked] = useState(false);
useEffect(() => {
const allNodes = getNodes(context.view);
allNodes.forEach(singNode => {
if (singNode.node.attrs.id === node.attrs.id) {
setChecked(singNode.node.attrs.correct);
}
});
}, [getNodes(context.view)]);
const handleChange = () => {
setChecked(!checked);
context.view.main.dispatch(
......@@ -46,4 +57,15 @@ const CustomSwitch = ({ node, getPos }) => {
);
};
const getNodes = view => {
const allNodes = DocumentHelpers.findBlockNodes(view.main.state.doc);
const multipleChoiceNodes = [];
allNodes.forEach(node => {
if (node.node.type.name === 'multiple_choice') {
multipleChoiceNodes.push(node);
}
});
return multipleChoiceNodes;
};
export default CustomSwitch;
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