diff --git a/editors/demo/src/HHMI/HHMI.js b/editors/demo/src/HHMI/HHMI.js index a30b810a302078879a380f80c16f6861672f5585..390a5dbf4e46ab63767c64c466eed957191e86e0 100644 --- a/editors/demo/src/HHMI/HHMI.js +++ b/editors/demo/src/HHMI/HHMI.js @@ -27,7 +27,7 @@ const Hhmi = () => { value={t} readonly layout={HhmiLayout} - // onChange={source => console.log(source)} + onChange={source => console.log(source)} /> </> ); diff --git a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/SwitchComponent.js b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/SwitchComponent.js index 4cc9b34090340e0d0a6be893e93a140626f740f6..b0464c6c82ac1e244d271e369dee885c9c6cef8e 100644 --- a/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/SwitchComponent.js +++ b/wax-prosemirror-services/src/MultipleChoiceQuestionService/components/SwitchComponent.js @@ -26,6 +26,7 @@ const StyledSwitch = styled(Switch)` const CustomSwitch = ({ node, getPos }) => { const context = useContext(WaxContext); const [checked, setChecked] = useState(false); + const [checkedAnswerMode, setCheckedAnswerMode] = useState(false); const { view, view: { main }, @@ -35,8 +36,6 @@ const CustomSwitch = ({ node, getPos }) => { return editable; }); - console.log(isEditable); - useEffect(() => { const allNodes = getNodes(main); allNodes.forEach(singNode => { @@ -48,22 +47,32 @@ const CustomSwitch = ({ node, getPos }) => { const handleChange = () => { setChecked(!checked); + setCheckedAnswerMode(!checkedAnswerMode); const allNodes = getNodes(main); allNodes.forEach(singleNode => { if (singleNode.node.attrs.id === node.attrs.id) { - main.dispatch( - main.state.tr.setNodeMarkup(getPos(), undefined, { - ...singleNode.node.attrs, - correct: !checked, - }), - ); + if (isEditable) { + main.dispatch( + main.state.tr.setNodeMarkup(getPos(), undefined, { + ...singleNode.node.attrs, + correct: !checked, + }), + ); + } else { + main.dispatch( + main.state.tr.setNodeMarkup(getPos(), undefined, { + ...singleNode.node.attrs, + correctAnswer: !checkedAnswerMode, + }), + ); + } } }); }; return ( <StyledSwitch - checked={isEditable ? checked : false} + checked={isEditable ? checked : checkedAnswerMode} checkedChildren="YES" label="Correct?" labelPosition="left"