From 62cb04d60de3fcfe32118b800fda1fa4b2d0e017 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Thu, 9 Nov 2023 11:14:30 +0200
Subject: [PATCH] add option to context and trigger update

---
 .../NumericalAnswerContainerComponent.js         | 10 ++++++++--
 .../NumericalAnswerDropDownCompontent.js         | 16 +++++++++-------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js
index a4f37b379..62954e27f 100644
--- a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js
+++ b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js
@@ -30,7 +30,9 @@ const NumericalAnswerContainerTool = styled.div`
   }
 `;
 
-const NumericalAnswerOption = styled.div``;
+const NumericalAnswerOption = styled.div`
+  padding: 8px;
+`;
 
 const ActionButton = styled.button`
   background: transparent;
@@ -80,6 +82,8 @@ export default ({ node, view, getPos }) => {
     });
   };
 
+  console.log(context.options.numericalAnswer);
+
   return (
     <NumericalAnswerWrapper>
       <div>
@@ -98,7 +102,9 @@ export default ({ node, view, getPos }) => {
       </div>
       <NumericalAnswerContainer className="numerical-answer">
         <EditorComponent getPos={getPos} node={node} view={view} />
-        <NumericalAnswerOption>Selected Option</NumericalAnswerOption>
+        <NumericalAnswerOption>
+          {!context.options?.numericalAnswer && <>No Type Selected</>}
+        </NumericalAnswerOption>
         {!testMode && !(readOnly && feedback === '') && (
           <FeedbackComponent
             getPos={getPos}
diff --git a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerDropDownCompontent.js b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerDropDownCompontent.js
index a9a817300..414c93083 100644
--- a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerDropDownCompontent.js
+++ b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerDropDownCompontent.js
@@ -26,7 +26,7 @@ const DropDownButton = styled.button`
   cursor: ${props => (props.disabled ? 'not-allowed' : 'pointer')};
   display: flex;
   position: relative;
-  width: 210px;
+  width: 235px;
   height: 26px;
 
   span {
@@ -45,7 +45,7 @@ const DropDownMenu = styled.div`
   box-shadow: 0 0.2rem 0.4rem rgb(0 0 0 / 10%);
   margin: 2px auto auto;
   position: absolute;
-  width: 210px;
+  width: 235px;
   max-height: 150px;
   overflow-y: auto;
   z-index: 2;
@@ -109,11 +109,11 @@ const NumericalAnswerDropDownCompontent = ({ view = {}, item }) => {
   useEffect(() => {
     setLabel('Select Type');
     dropDownOptions.forEach(option => {
-      //   if (option.item.active(main.state)) {
-      //     setLabel(option.label);
-      //   }
+      if (context.options?.numericalAnswer === option.value) {
+        setLabel(option.label);
+      }
     });
-  }, [activeViewId]);
+  }, []);
 
   let isDisabled = false;
 
@@ -161,7 +161,9 @@ const NumericalAnswerDropDownCompontent = ({ view = {}, item }) => {
   };
 
   const onChange = option => {
-    tools[option.value].run(main, context);
+    context.setOption({ numericalAnswer: option.value });
+    main.dispatch(main.state.tr.setMeta('addToHistory', false));
+    setLabel(option.label);
     openCloseMenu();
   };
 
-- 
GitLab