From 9e5465fcff9225ce86b7f850fbf7064881afaf43 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Fri, 12 Jan 2024 17:32:06 +0200
Subject: [PATCH] temp for deleting multiple choice option

---
 .../components/AnswerComponent.js             | 22 ++++++++++++++++++-
 .../components/AnswerComponent.js             | 22 ++++++++++++++++++-
 .../components/AnswerComponent.js             | 22 ++++++++++++++++++-
 .../components/AnswerComponent.js             | 22 ++++++++++++++++++-
 .../components/DropDownComponent.js           |  1 -
 5 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/wax-questions-service/src/MultipleChoiceQuestionService/MultipleChoiceSingleCorrectQuestionService/components/AnswerComponent.js b/wax-questions-service/src/MultipleChoiceQuestionService/MultipleChoiceSingleCorrectQuestionService/components/AnswerComponent.js
index e7005a3d1..ceaa25f7a 100644
--- a/wax-questions-service/src/MultipleChoiceQuestionService/MultipleChoiceSingleCorrectQuestionService/components/AnswerComponent.js
+++ b/wax-questions-service/src/MultipleChoiceQuestionService/MultipleChoiceSingleCorrectQuestionService/components/AnswerComponent.js
@@ -131,10 +131,30 @@ export default ({ node, view, getPos }) => {
     };
   }, []);
 
+  // const removeOption = () => {
+  //   const answersCount = findAnswerCount();
+  //   if (answersCount.count >= 1) {
+  //     main.state.doc.nodesBetween(getPos(), getPos() + 1, (sinlgeNode, pos) => {
+  //       if (sinlgeNode.attrs.id === node.attrs.id) {
+  //         main.dispatch(
+  //           main.state.tr.deleteRange(getPos(), getPos() + sinlgeNode.nodeSize),
+  //         );
+  //       }
+  //     });
+  //   } else {
+  //     main.dispatch(
+  //       main.state.tr.setSelection(
+  //         NodeSelection.create(main.state.doc, answersCount.parentPosition),
+  //       ),
+  //     );
+  //     main.dispatch(main.state.tr.deleteSelection());
+  //   }
+  // };
+
   const removeOption = () => {
     const answersCount = findAnswerCount();
     if (answersCount.count >= 1) {
-      main.state.doc.nodesBetween(getPos(), getPos() + 1, (sinlgeNode, pos) => {
+      answersCount.parentContainer.content.content.forEach(sinlgeNode => {
         if (sinlgeNode.attrs.id === node.attrs.id) {
           main.dispatch(
             main.state.tr.deleteRange(getPos(), getPos() + sinlgeNode.nodeSize),
diff --git a/wax-questions-service/src/MultipleChoiceQuestionService/TrueFalseQuestionService/components/AnswerComponent.js b/wax-questions-service/src/MultipleChoiceQuestionService/TrueFalseQuestionService/components/AnswerComponent.js
index 8c7af5e73..160b67ab3 100644
--- a/wax-questions-service/src/MultipleChoiceQuestionService/TrueFalseQuestionService/components/AnswerComponent.js
+++ b/wax-questions-service/src/MultipleChoiceQuestionService/TrueFalseQuestionService/components/AnswerComponent.js
@@ -131,10 +131,30 @@ export default ({ node, view, getPos }) => {
     };
   }, []);
 
+  // const removeOption = () => {
+  //   const answersCount = findAnswerCount();
+  //   if (answersCount.count >= 1) {
+  //     main.state.doc.nodesBetween(getPos(), getPos() + 1, (sinlgeNode, pos) => {
+  //       if (sinlgeNode.attrs.id === node.attrs.id) {
+  //         main.dispatch(
+  //           main.state.tr.deleteRange(getPos(), getPos() + sinlgeNode.nodeSize),
+  //         );
+  //       }
+  //     });
+  //   } else {
+  //     main.dispatch(
+  //       main.state.tr.setSelection(
+  //         NodeSelection.create(main.state.doc, answersCount.parentPosition),
+  //       ),
+  //     );
+  //     main.dispatch(main.state.tr.deleteSelection());
+  //   }
+  // };
+
   const removeOption = () => {
     const answersCount = findAnswerCount();
     if (answersCount.count >= 1) {
-      main.state.doc.nodesBetween(getPos(), getPos() + 1, (sinlgeNode, pos) => {
+      answersCount.parentContainer.content.content.forEach(sinlgeNode => {
         if (sinlgeNode.attrs.id === node.attrs.id) {
           main.dispatch(
             main.state.tr.deleteRange(getPos(), getPos() + sinlgeNode.nodeSize),
diff --git a/wax-questions-service/src/MultipleChoiceQuestionService/TrueFalseSingleCorrectQuestionService/components/AnswerComponent.js b/wax-questions-service/src/MultipleChoiceQuestionService/TrueFalseSingleCorrectQuestionService/components/AnswerComponent.js
index 818aca43e..08a653559 100644
--- a/wax-questions-service/src/MultipleChoiceQuestionService/TrueFalseSingleCorrectQuestionService/components/AnswerComponent.js
+++ b/wax-questions-service/src/MultipleChoiceQuestionService/TrueFalseSingleCorrectQuestionService/components/AnswerComponent.js
@@ -131,10 +131,30 @@ export default ({ node, view, getPos }) => {
     };
   }, []);
 
+  // const removeOption = () => {
+  //   const answersCount = findAnswerCount();
+  //   if (answersCount.count >= 1) {
+  //     main.state.doc.nodesBetween(getPos(), getPos() + 1, (sinlgeNode, pos) => {
+  //       if (sinlgeNode.attrs.id === node.attrs.id) {
+  //         main.dispatch(
+  //           main.state.tr.deleteRange(getPos(), getPos() + sinlgeNode.nodeSize),
+  //         );
+  //       }
+  //     });
+  //   } else {
+  //     main.dispatch(
+  //       main.state.tr.setSelection(
+  //         NodeSelection.create(main.state.doc, answersCount.parentPosition),
+  //       ),
+  //     );
+  //     main.dispatch(main.state.tr.deleteSelection());
+  //   }
+  // };
+
   const removeOption = () => {
     const answersCount = findAnswerCount();
     if (answersCount.count >= 1) {
-      main.state.doc.nodesBetween(getPos(), getPos() + 1, (sinlgeNode, pos) => {
+      answersCount.parentContainer.content.content.forEach(sinlgeNode => {
         if (sinlgeNode.attrs.id === node.attrs.id) {
           main.dispatch(
             main.state.tr.deleteRange(getPos(), getPos() + sinlgeNode.nodeSize),
diff --git a/wax-questions-service/src/MultipleChoiceQuestionService/components/AnswerComponent.js b/wax-questions-service/src/MultipleChoiceQuestionService/components/AnswerComponent.js
index b4325141b..1110f5481 100644
--- a/wax-questions-service/src/MultipleChoiceQuestionService/components/AnswerComponent.js
+++ b/wax-questions-service/src/MultipleChoiceQuestionService/components/AnswerComponent.js
@@ -130,10 +130,30 @@ export default ({ node, view, getPos }) => {
     };
   }, []);
 
+  // const removeOption = () => {
+  //   const answersCount = findAnswerCount();
+  //   if (answersCount.count >= 1) {
+  //     main.state.doc.nodesBetween(getPos(), getPos() + 1, sinlgeNode => {
+  //       if (sinlgeNode.attrs.id === node.attrs.id) {
+  //         main.dispatch(
+  //           main.state.tr.deleteRange(getPos(), getPos() + sinlgeNode.nodeSize),
+  //         );
+  //       }
+  //     });
+  //   } else {
+  //     main.dispatch(
+  //       main.state.tr.setSelection(
+  //         NodeSelection.create(main.state.doc, answersCount.parentPosition),
+  //       ),
+  //     );
+  //     main.dispatch(main.state.tr.deleteSelection());
+  //   }
+  // };
+
   const removeOption = () => {
     const answersCount = findAnswerCount();
     if (answersCount.count >= 1) {
-      main.state.doc.nodesBetween(getPos(), getPos() + 1, sinlgeNode => {
+      answersCount.parentContainer.content.content.forEach(sinlgeNode => {
         if (sinlgeNode.attrs.id === node.attrs.id) {
           main.dispatch(
             main.state.tr.deleteRange(getPos(), getPos() + sinlgeNode.nodeSize),
diff --git a/wax-questions-service/src/MultipleDropDownService/components/DropDownComponent.js b/wax-questions-service/src/MultipleDropDownService/components/DropDownComponent.js
index f52cc6b88..56cc6b437 100644
--- a/wax-questions-service/src/MultipleDropDownService/components/DropDownComponent.js
+++ b/wax-questions-service/src/MultipleDropDownService/components/DropDownComponent.js
@@ -119,7 +119,6 @@ export default ({ setPosition, position }) => {
     const { from } = selection;
     const WaxSurface = activeView.dom.getBoundingClientRect();
     const start = activeView.coordsAtPos(from);
-    console.log(start, WaxSurface.top);
     const left = start.left - WaxSurface.left - 75;
     const top = start.top - WaxSurface.top + 25;
     setPosition({ ...position, left, top });
-- 
GitLab