From aae07055e6b69d79d8924798ea5214b5ec47bcd0 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Tue, 17 May 2022 19:01:40 +0300
Subject: [PATCH] save correct value for matching

---
 .../components/DropDownComponent.js           | 19 +++++--------------
 .../schema/matchingOptionNode.js              |  9 ++++++---
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/wax-prosemirror-services/src/MatchingService/components/DropDownComponent.js b/wax-prosemirror-services/src/MatchingService/components/DropDownComponent.js
index 7c2c287db..aa7a3c9f6 100644
--- a/wax-prosemirror-services/src/MatchingService/components/DropDownComponent.js
+++ b/wax-prosemirror-services/src/MatchingService/components/DropDownComponent.js
@@ -53,14 +53,15 @@ const DropComponent = ({ getPos, node, view }) => {
     setSelectedOption(option);
 
     const allNodes = getNodes(main);
+    console.log(allNodes);
     allNodes.forEach(singleNode => {
-      if (singleNode.attrs.id === node.attrs.id) {
+      if (singleNode.node.attrs.id === node.attrs.id) {
         main.dispatch(
           main.state.tr
             .setMeta('addToHistory', false)
-            .setNodeMarkup(getPos() + 3, undefined, {
+            .setNodeMarkup(singleNode.pos, undefined, {
               ...singleNode.attrs,
-              answer: option,
+              correct: option.value,
             }),
         );
       }
@@ -100,15 +101,5 @@ const DropComponent = ({ getPos, node, view }) => {
 export default DropComponent;
 
 const getNodes = view => {
-  const allNodes = DocumentHelpers.findBlockNodes(view.state.doc);
-  const matchingOptions = [];
-  allNodes.forEach(node => {
-    if (node.node.type.name === 'paragraph') {
-      node.node.content.content.forEach(optionNode => {
-        if (optionNode.type.name === 'matching_option')
-          matchingOptions.push(optionNode);
-      });
-    }
-  });
-  return matchingOptions;
+  return DocumentHelpers.findInlineNodes(view.state.doc);
 };
diff --git a/wax-prosemirror-services/src/MatchingService/schema/matchingOptionNode.js b/wax-prosemirror-services/src/MatchingService/schema/matchingOptionNode.js
index 45283958c..5b8b51b14 100644
--- a/wax-prosemirror-services/src/MatchingService/schema/matchingOptionNode.js
+++ b/wax-prosemirror-services/src/MatchingService/schema/matchingOptionNode.js
@@ -3,7 +3,8 @@ const matchingOptionNode = {
     class: { default: 'matching-option' },
     id: { default: '' },
     isfirst: { default: false },
-    answer: { default: {} },
+    answer: { default: '' },
+    correct: { default: '' },
     options: { default: [] },
   },
   group: 'inline questions',
@@ -19,7 +20,8 @@ const matchingOptionNode = {
           id: dom.getAttribute('id'),
           class: dom.getAttribute('class'),
           isfirst: JSON.parse(dom.getAttribute('isfirst').toLowerCase()),
-          answer: JSON.parse(dom.getAttribute('answer').toLowerCase()),
+          answer: dom.getAttribute('answer'),
+          correct: dom.getAttribute('correct'),
         };
       },
     },
@@ -31,7 +33,8 @@ const matchingOptionNode = {
         id: node.attrs.id,
         class: node.attrs.class,
         isfirst: node.attrs.isfirst,
-        answer: JSON.stringify(node.attrs.answer),
+        answer: node.attrs.answer,
+        correct: node.attrs.correct,
         feedback: node.attrs.feedback,
       },
       0,
-- 
GitLab