From b4b3ac16a87371c2590f98a665c670639b723ff9 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Fri, 3 Sep 2021 17:43:20 +0300
Subject: [PATCH] set Checked

---
 .../components/FeedbackComponent.js                |  5 +----
 .../components/QuestionComponent.js                |  2 +-
 .../components/SwitchComponent.js                  | 14 ++++++++++++--
 .../src/PortalService/AbstractNodeView.js          |  2 +-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/FeedbackComponent.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/FeedbackComponent.js
index 26e1ee0b5..4c3b79cdc 100644
--- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/FeedbackComponent.js
+++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/FeedbackComponent.js
@@ -21,10 +21,7 @@ const FeedBackInput = styled.input`
 
 export default ({ node, view, getPos }) => {
   const context = useContext(WaxContext);
-  const {
-    view: { main },
-    activeViewId,
-  } = context;
+  const { activeViewId } = context;
   const [feedBack, setFeedBack] = useState(node.attrs.feedback);
   const feedBackRef = useRef(null);
 
diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/QuestionComponent.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/QuestionComponent.js
index 8ea0fe621..e0593fac1 100644
--- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/QuestionComponent.js
+++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/QuestionComponent.js
@@ -132,7 +132,7 @@ export default ({ node, view, getPos }) => {
           <QuestionData>
             <EditorComponent node={node} view={view} getPos={getPos} />
 
-            <SwitchComponent node={node} />
+            <SwitchComponent node={node} getPos={getPos} />
           </QuestionData>
           <FeedbackComponent node={node} view={view} getPos={getPos} />
         </QuestionWrapper>
diff --git a/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/SwitchComponent.js b/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/SwitchComponent.js
index 2c57ba246..702ae2226 100644
--- a/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/SwitchComponent.js
+++ b/editors/demo/src/HHMI/MultipleChoiceQuestionService/components/SwitchComponent.js
@@ -1,4 +1,5 @@
-import React, { useState } from 'react';
+import React, { useState, useContext } from 'react';
+import { WaxContext } from 'wax-prosemirror-core';
 import styled from 'styled-components';
 import Switch from './Switch';
 
@@ -19,10 +20,19 @@ const StyledSwitch = styled(Switch)`
   }
 `;
 
-const CustomSwitch = ({ node }) => {
+const CustomSwitch = ({ node, getPos }) => {
+  const context = useContext(WaxContext);
+  const { activeViewId } = context;
   const [checked, setChecked] = useState(false);
+
   const handleChange = () => {
     setChecked(!checked);
+    context.view.main.dispatch(
+      context.view.main.state.tr.setNodeMarkup(getPos(), undefined, {
+        ...node.attrs,
+        correct: !checked,
+      }),
+    );
   };
 
   return (
diff --git a/wax-prosemirror-services/src/PortalService/AbstractNodeView.js b/wax-prosemirror-services/src/PortalService/AbstractNodeView.js
index d51b293b3..8542284b2 100644
--- a/wax-prosemirror-services/src/PortalService/AbstractNodeView.js
+++ b/wax-prosemirror-services/src/PortalService/AbstractNodeView.js
@@ -23,7 +23,7 @@ export default class AbstractNodeView {
   }
 
   update(node) {
-    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];
-- 
GitLab