From 6c4231f86e9efe3a180d24768aadcf23d8ad9cbd Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Wed, 1 Dec 2021 18:15:50 +0200
Subject: [PATCH] remove files

---
 .../components/Button.js                      |  88 ----------
 .../components/EditorComponent.js             | 157 ------------------
 .../components/QuestionComponent.js           |  24 +--
 .../components/Switch.js                      |  52 ------
 .../components/SwitchComponent.js             |  26 +--
 ...ultipleChoiceSingleCorrectContainerNode.js |   4 +-
 .../components/Switch.js                      |  52 ------
 .../components/SwitchComponent.js             |   2 +-
 8 files changed, 23 insertions(+), 382 deletions(-)
 delete mode 100644 wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/Button.js
 delete mode 100644 wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/EditorComponent.js
 delete mode 100644 wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/Switch.js
 delete mode 100644 wax-prosemirror-services/src/TrueFalseQuestionService/components/Switch.js

diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/Button.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/Button.js
deleted file mode 100644
index 7d1619944..000000000
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/Button.js
+++ /dev/null
@@ -1,88 +0,0 @@
-import React from 'react';
-import styled, { css } from 'styled-components';
-import PropTypes from 'prop-types';
-import { Button as AntButton } from 'antd';
-import { omit } from 'lodash';
-
-import { darken, lighten } from '@pubsweet/ui-toolkit';
-
-const colors = {
-  danger: 'colorError',
-  error: 'colorError',
-  success: 'colorSuccess',
-  // warn: 'colorWarning',
-};
-
-const StyledButton = styled(AntButton)`
-  ${props => {
-    const { status, theme, type } = props;
-    if (!Object.keys(colors).includes(status)) return null;
-    const color = theme[colors[status]];
-
-    // primary
-    if (type === 'primary')
-      return css`
-        background-color: ${color};
-        border-color: ${color};
-        color: ${theme.colorTextReverse};
-
-        &:hover,
-        &:focus,
-        &:active {
-          border-color: ${color};
-          color: ${theme.colorTextReverse};
-        }
-
-        &:hover,
-        &:focus {
-          background-color: ${lighten(color, 0.25)};
-        }
-
-        &:active {
-          background-color: ${darken(color, 0.25)};
-        }
-      `;
-
-    // non-primary
-    return css`
-      color: ${color};
-      border-color: ${color};
-      &:hover,
-      &:focus {
-        color: ${lighten(color, 0.25)};
-        border-color: ${lighten(color, 0.25)};
-      }
-
-      &:active {
-        color: ${darken(color, 0.25)};
-        border-color: ${darken(color, 0.25)};
-      }
-    `;
-  }}
-`;
-/**
- * API is the same as https://ant.design/components/button/#API, except for the
- * `danger` prop, which is ommited in favour of `status`, described below.
- */
-
-const Button = props => {
-  const { children, className, ...rest } = props;
-  const passProps = omit(rest, 'danger');
-
-  return (
-    // eslint-disable-next-line react/jsx-props-no-spreading
-    <StyledButton className={className} {...passProps}>
-      {children}
-    </StyledButton>
-  );
-};
-
-Button.propTypes = {
-  status: PropTypes.oneOf(['error', 'danger', 'success']),
-};
-
-Button.defaultProps = {
-  status: null,
-};
-
-export default Button;
diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/EditorComponent.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/EditorComponent.js
deleted file mode 100644
index 68add35be..000000000
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/EditorComponent.js
+++ /dev/null
@@ -1,157 +0,0 @@
-/* eslint-disable react/destructuring-assignment */
-/* eslint-disable react/prop-types */
-
-import React, { useContext, useRef, useEffect } from 'react';
-import styled from 'styled-components';
-import { EditorView } from 'prosemirror-view';
-import { EditorState, TextSelection } from 'prosemirror-state';
-import { StepMap } from 'prosemirror-transform';
-import { keymap } from 'prosemirror-keymap';
-import { baseKeymap } from 'prosemirror-commands';
-import { undo, redo } from 'prosemirror-history';
-import { WaxContext } from 'wax-prosemirror-core';
-import Placeholder from '../../MultipleChoiceQuestionService/plugins/placeholder';
-
-const EditorWrapper = styled.div`
-  border: none;
-  display: flex;
-  flex: 2 1 auto;
-  justify-content: left;
-
-  .ProseMirror {
-    white-space: break-spaces;
-    width: 100%;
-    word-wrap: break-word;
-
-    &:focus {
-      outline: none;
-    }
-
-    p.empty-node:first-child::before {
-      content: attr(data-content);
-    }
-
-    .empty-node::before {
-      color: rgb(170, 170, 170);
-      float: left;
-      font-style: italic;
-      height: 0px;
-      pointer-events: none;
-    }
-  }
-`;
-
-const EditorComponent = ({ node, view, getPos }) => {
-  const editorRef = useRef();
-
-  const context = useContext(WaxContext);
-  let questionView;
-  const questionId = node.attrs.id;
-  const isEditable = context.view.main.props.editable(editable => {
-    return editable;
-  });
-
-  let finalPlugins = [];
-
-  const createKeyBindings = () => {
-    const keys = getKeys();
-    Object.keys(baseKeymap).forEach(key => {
-      keys[key] = baseKeymap[key];
-    });
-    return keys;
-  };
-
-  const getKeys = () => {
-    return {
-      'Mod-z': () => undo(view.state, view.dispatch),
-      'Mod-y': () => redo(view.state, view.dispatch),
-    };
-  };
-
-  const plugins = [keymap(createKeyBindings()), ...context.app.getPlugins()];
-
-  // eslint-disable-next-line no-shadow
-  const createPlaceholder = placeholder => {
-    return Placeholder({
-      content: placeholder,
-    });
-  };
-
-  finalPlugins = finalPlugins.concat([
-    createPlaceholder('Type your answer'),
-    ...plugins,
-  ]);
-
-  useEffect(() => {
-    questionView = new EditorView(
-      {
-        mount: editorRef.current,
-      },
-      {
-        editable: () => isEditable,
-        state: EditorState.create({
-          doc: node,
-          plugins: finalPlugins,
-        }),
-        // This is the magic part
-        dispatchTransaction,
-        disallowedTools: ['Images', 'Lists', 'lift', 'MultipleChoice'],
-        handleDOMEvents: {
-          mousedown: () => {
-            context.view.main.dispatch(
-              context.view.main.state.tr.setSelection(
-                new TextSelection(
-                  context.view.main.state.tr.doc.resolve(getPos() + 2),
-                ),
-              ),
-            );
-            context.updateView({}, questionId);
-            // Kludge to prevent issues due to the fact that the whole
-            // footnote is node-selected (and thus DOM-selected) when
-            // the parent editor is focused.
-            if (questionView.hasFocus()) questionView.focus();
-          },
-        },
-
-        attributes: {
-          spellcheck: 'false',
-        },
-      },
-    );
-
-    // Set Each note into Wax's Context
-    context.updateView(
-      {
-        [questionId]: questionView,
-      },
-      questionId,
-    );
-    if (questionView.hasFocus()) questionView.focus();
-  }, []);
-
-  const dispatchTransaction = tr => {
-    const { state, transactions } = questionView.state.applyTransaction(tr);
-    questionView.updateState(state);
-    context.updateView({}, questionId);
-
-    if (!tr.getMeta('fromOutside')) {
-      const outerTr = view.state.tr;
-      const offsetMap = StepMap.offset(getPos() + 1);
-      for (let i = 0; i < transactions.length; i++) {
-        const { steps } = transactions[i];
-        for (let j = 0; j < steps.length; j++)
-          outerTr.step(steps[j].map(offsetMap));
-      }
-      if (outerTr.docChanged)
-        view.dispatch(outerTr.setMeta('outsideView', questionId));
-    }
-  };
-
-  return (
-    <EditorWrapper>
-      <div ref={editorRef} />
-    </EditorWrapper>
-  );
-};
-
-export default EditorComponent;
diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/QuestionComponent.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/QuestionComponent.js
index 91d8e6b3d..794c354d2 100644
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/QuestionComponent.js
+++ b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/QuestionComponent.js
@@ -7,10 +7,10 @@ import { PlusSquareOutlined, DeleteOutlined } from '@ant-design/icons';
 import { Fragment } from 'prosemirror-model';
 import { v4 as uuidv4 } from 'uuid';
 import helpers from '../../MultipleChoiceQuestionService/helpers/helpers';
-import EditorComponent from './EditorComponent';
-import SwitchComponent from './SwitchComponent';
+import EditorComponent from '../../MultipleChoiceQuestionService/components/EditorComponent';
 import FeedbackComponent from '../../MultipleChoiceQuestionService/components/FeedbackComponent';
-import Button from './Button';
+import Button from '../../MultipleChoiceQuestionService/components/Button';
+import SwitchComponent from './SwitchComponent';
 
 const Wrapper = styled.div`
   display: flex;
@@ -120,18 +120,6 @@ export default ({ node, view, getPos }) => {
     });
   };
 
-  const getIsDisabled = () => {
-    context.view.main.state.doc.descendants((editorNode, index) => {
-      if (editorNode.type.name === 'multiple_choice_single_correct_container') {
-        editorNode.content.content.forEach(element => {
-          if (element.attrs.correct) {
-            console.log(element);
-          }
-        });
-      }
-    });
-  };
-
   const readOnly = !isEditable;
   const showAddIcon = true;
   const showRemoveIcon = true;
@@ -141,11 +129,7 @@ export default ({ node, view, getPos }) => {
       <QuestionControlsWrapper>
         <InfoRow>
           <QuestionNunber />
-          <SwitchComponent
-            getPos={getPos}
-            isDisabled={getIsDisabled()}
-            node={node}
-          />
+          <SwitchComponent getPos={getPos} node={node} />
         </InfoRow>
         <QuestionWrapper>
           <QuestionData>
diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/Switch.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/Switch.js
deleted file mode 100644
index 6cad91dad..000000000
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/Switch.js
+++ /dev/null
@@ -1,52 +0,0 @@
-import React from 'react';
-import PropTypes from 'prop-types';
-import styled, { css } from 'styled-components';
-import { Switch as AntSwitch } from 'antd';
-
-import { grid } from '@pubsweet/ui-toolkit';
-
-const Wrapper = styled.span``;
-
-const Label = styled.span`
-  ${props =>
-    props.labelPosition === 'left' &&
-    css`
-      margin-right: ${grid(2)};
-    `}
-
-  ${props =>
-    props.labelPosition === 'right' &&
-    css`
-      margin-left: ${grid(2)};
-    `}
-`;
-
-const Switch = props => {
-  const { className, label, labelPosition, ...rest } = props;
-
-  return (
-    <Wrapper className={className}>
-      {label && labelPosition === 'left' && (
-        <Label labelPosition={labelPosition}>{label}</Label>
-      )}
-
-      <AntSwitch {...rest} />
-
-      {label && labelPosition === 'right' && (
-        <Label labelPosition={labelPosition}>{label}</Label>
-      )}
-    </Wrapper>
-  );
-};
-
-Switch.propTypes = {
-  label: PropTypes.string,
-  labelPosition: PropTypes.string,
-};
-
-Switch.defaultProps = {
-  label: null,
-  labelPosition: 'right',
-};
-
-export default Switch;
diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js
index f0db85d5a..8adba6f48 100644
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js
+++ b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js
@@ -4,7 +4,7 @@ import React, { useState, useContext, useEffect } from 'react';
 import { WaxContext } from 'wax-prosemirror-core';
 import { DocumentHelpers } from 'wax-prosemirror-utilities';
 import styled from 'styled-components';
-import Switch from './Switch';
+import Switch from '../../MultipleChoiceQuestionService/components/Switch';
 
 const StyledSwitch = styled(Switch)`
   display: flex;
@@ -38,15 +38,21 @@ const CustomSwitch = ({ node, getPos }) => {
 
   const handleChange = () => {
     setChecked(!checked);
-    const allNodes = getNodes(context.view.main);
-    allNodes.forEach(singleNode => {
-      if (singleNode.node.attrs.id === node.attrs.id) {
-        context.view.main.dispatch(
-          context.view.main.state.tr.setNodeMarkup(getPos(), undefined, {
-            ...singleNode.node.attrs,
-            correct: !checked,
-          }),
-        );
+
+    context.view.main.state.doc.descendants((editorNode, index) => {
+      if (editorNode.type.name === 'multiple_choice_single_correct_container') {
+        editorNode.content.content.forEach(element => {
+          if (element.attrs.id === node.attrs.id) {
+            context.view.main.dispatch(
+              context.view.main.state.tr.setNodeMarkup(getPos(), undefined, {
+                ...element.attrs,
+                correct: !checked,
+              }),
+            );
+          } else {
+            console.log('in else');
+          }
+        });
       }
     });
   };
diff --git a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/schema/multipleChoiceSingleCorrectContainerNode.js b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/schema/multipleChoiceSingleCorrectContainerNode.js
index c45138788..2f84777aa 100644
--- a/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/schema/multipleChoiceSingleCorrectContainerNode.js
+++ b/wax-prosemirror-services/src/MultipleChoiceSingleCorrectQuestionService/schema/multipleChoiceSingleCorrectContainerNode.js
@@ -2,7 +2,7 @@ const multipleChoiceSingleCorrectContainerNode = {
   attrs: {
     id: { default: '' },
     class: { default: 'multiple-choice-single-correct' },
-    singleCorrect: { default: true },
+    correctId: { default: '' },
   },
   group: 'block questions',
   atom: true,
@@ -16,7 +16,7 @@ const multipleChoiceSingleCorrectContainerNode = {
         return {
           id: dom.dataset.id,
           class: dom.getAttribute('class'),
-          singleCorrect: dom.getAttribute('singleCorrect'),
+          correctId: dom.getAttribute('singleCorrect'),
         };
       },
     },
diff --git a/wax-prosemirror-services/src/TrueFalseQuestionService/components/Switch.js b/wax-prosemirror-services/src/TrueFalseQuestionService/components/Switch.js
deleted file mode 100644
index 6cad91dad..000000000
--- a/wax-prosemirror-services/src/TrueFalseQuestionService/components/Switch.js
+++ /dev/null
@@ -1,52 +0,0 @@
-import React from 'react';
-import PropTypes from 'prop-types';
-import styled, { css } from 'styled-components';
-import { Switch as AntSwitch } from 'antd';
-
-import { grid } from '@pubsweet/ui-toolkit';
-
-const Wrapper = styled.span``;
-
-const Label = styled.span`
-  ${props =>
-    props.labelPosition === 'left' &&
-    css`
-      margin-right: ${grid(2)};
-    `}
-
-  ${props =>
-    props.labelPosition === 'right' &&
-    css`
-      margin-left: ${grid(2)};
-    `}
-`;
-
-const Switch = props => {
-  const { className, label, labelPosition, ...rest } = props;
-
-  return (
-    <Wrapper className={className}>
-      {label && labelPosition === 'left' && (
-        <Label labelPosition={labelPosition}>{label}</Label>
-      )}
-
-      <AntSwitch {...rest} />
-
-      {label && labelPosition === 'right' && (
-        <Label labelPosition={labelPosition}>{label}</Label>
-      )}
-    </Wrapper>
-  );
-};
-
-Switch.propTypes = {
-  label: PropTypes.string,
-  labelPosition: PropTypes.string,
-};
-
-Switch.defaultProps = {
-  label: null,
-  labelPosition: 'right',
-};
-
-export default Switch;
diff --git a/wax-prosemirror-services/src/TrueFalseQuestionService/components/SwitchComponent.js b/wax-prosemirror-services/src/TrueFalseQuestionService/components/SwitchComponent.js
index 78879f53d..162d30a4a 100644
--- a/wax-prosemirror-services/src/TrueFalseQuestionService/components/SwitchComponent.js
+++ b/wax-prosemirror-services/src/TrueFalseQuestionService/components/SwitchComponent.js
@@ -4,7 +4,7 @@ import React, { useState, useContext, useEffect } from 'react';
 import { WaxContext } from 'wax-prosemirror-core';
 import { DocumentHelpers } from 'wax-prosemirror-utilities';
 import styled from 'styled-components';
-import Switch from './Switch';
+import Switch from '../../MultipleChoiceQuestionService/components/Switch';
 
 const StyledSwitch = styled(Switch)`
   display: flex;
-- 
GitLab