From 2036fb521dbe58b0ba02ec99c6bb38aafe2f1761 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Wed, 24 Nov 2021 12:15:09 +0200
Subject: [PATCH] set correct nodeType

---
 .../components/FeedbackComponent.js            |  2 +-
 .../components/QuestionComponent.js            | 18 +++++++++++++++---
 .../components/SwitchComponent.js              |  4 ++--
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/FeedbackComponent.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/FeedbackComponent.js
index 0fa7d157c..a5c7273e7 100644
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/FeedbackComponent.js
+++ b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/FeedbackComponent.js
@@ -102,7 +102,7 @@ const getNodes = view => {
   const allNodes = DocumentHelpers.findBlockNodes(view.state.doc);
   const multipleChoiceNodes = [];
   allNodes.forEach(node => {
-    if (node.node.type.name === 'multiple_choice') {
+    if (node.node.type.name === 'multiple_choice_single_correct') {
       multipleChoiceNodes.push(node);
     }
   });
diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/QuestionComponent.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/QuestionComponent.js
index cc00ad244..7f3e507c5 100644
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/QuestionComponent.js
+++ b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/QuestionComponent.js
@@ -92,7 +92,7 @@ export default ({ node, view, getPos }) => {
   const addOption = nodeId => {
     const newAnswerId = uuidv4();
     context.view.main.state.doc.descendants((editorNode, index) => {
-      if (editorNode.type.name === 'multiple_choice') {
+      if (editorNode.type.name === 'multiple_choice_single_correct') {
         if (editorNode.attrs.id === nodeId) {
           context.view.main.dispatch(
             context.view.main.state.tr.setSelection(
@@ -104,7 +104,7 @@ export default ({ node, view, getPos }) => {
             ),
           );
 
-          const answerOption = context.view.main.state.config.schema.nodes.multiple_choice.create(
+          const answerOption = context.view.main.state.config.schema.nodes.multiple_choice_single_correct.create(
             { id: newAnswerId },
             Fragment.empty,
           );
@@ -120,6 +120,14 @@ export default ({ node, view, getPos }) => {
     });
   };
 
+  const getIsDisabled = () => {
+    context.view.main.state.doc.descendants((editorNode, index) => {
+      if (editorNode.type.name === 'multiple_choice_single_correct') {
+        console.log(editorNode);
+      }
+    });
+  };
+
   const readOnly = !isEditable;
   const showAddIcon = true;
   const showRemoveIcon = true;
@@ -129,7 +137,11 @@ export default ({ node, view, getPos }) => {
       <QuestionControlsWrapper>
         <InfoRow>
           <QuestionNunber />
-          <SwitchComponent getPos={getPos} node={node} />
+          <SwitchComponent
+            getPos={getPos}
+            node={node}
+            isDisabled={getIsDisabled()}
+          />
         </InfoRow>
         <QuestionWrapper>
           <QuestionData>
diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js
index 0d2b5c97b..f0db85d5a 100644
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js
+++ b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js
@@ -1,5 +1,5 @@
 /* eslint-disable react/prop-types */
-/* 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';
@@ -67,7 +67,7 @@ const getNodes = view => {
   const allNodes = DocumentHelpers.findBlockNodes(view.state.doc);
   const multipleChoiceNodes = [];
   allNodes.forEach(node => {
-    if (node.node.type.name === 'multiple_choice') {
+    if (node.node.type.name === 'multiple_choice_single_correct') {
       multipleChoiceNodes.push(node);
     }
   });
-- 
GitLab