From 2ae8d7ffb21e8bcc42731e8a4a61fe819f850478 Mon Sep 17 00:00:00 2001 From: mrfry Date: Sun, 21 Feb 2021 14:47:39 +0100 Subject: [PATCH] Complete project redo, got carried away, and forgot to commit during rewriting --- src/commonStyles.module.css | 52 ++ src/components/LoadingIndicator.js | 20 +- src/components/LoadingIndicator.module.css | 24 + src/components/Question.js | 187 ++++--- src/components/QuestionSearchResult.js | 150 +++--- src/components/Questions.js | 77 ++- src/components/Questions.module.css | 25 + src/components/Subject.js | 120 ++++- src/components/SubjectSelector.js | 2 + src/components/SubjectSelector.module.css | 3 + src/components/dbSelector.js | 28 ++ src/components/possibleAnswers.js | 256 ++++++++++ src/components/possibleAnswers.module.css | 85 ++++ src/components/question.module.css | 46 +- src/components/questionAdder.js | 396 +++++++-------- src/components/questionAdder.module.css | 106 +--- .../questionSearchResult.module.css | 0 src/components/questionView.js | 207 +++++++- src/components/searchBar.js | 28 ++ src/components/searchBar.module.css | 27 + src/components/subject.module.css | 16 + src/components/subjectView.js | 226 +++++++-- src/components/subjectView.module.css | 30 +- src/components/testView.js | 189 +++++++ src/components/testView.module.css | 46 ++ src/constants.json | 3 +- src/pages/_app.js | 7 +- src/pages/index.js | 473 +++++++++--------- src/pages/index.module.css | 53 +- 29 files changed, 2007 insertions(+), 875 deletions(-) create mode 100644 src/commonStyles.module.css create mode 100644 src/components/LoadingIndicator.module.css create mode 100644 src/components/dbSelector.js create mode 100644 src/components/possibleAnswers.js create mode 100644 src/components/possibleAnswers.module.css create mode 100644 src/components/questionSearchResult.module.css create mode 100644 src/components/searchBar.js create mode 100644 src/components/searchBar.module.css create mode 100644 src/components/subject.module.css create mode 100644 src/components/testView.js create mode 100644 src/components/testView.module.css diff --git a/src/commonStyles.module.css b/src/commonStyles.module.css new file mode 100644 index 0000000..839a2b2 --- /dev/null +++ b/src/commonStyles.module.css @@ -0,0 +1,52 @@ +.actions { + display: flex; + justify-content: space-around; +} + +.actions > div { + cursor: pointer; + padding: 5px 20px; + + color: #eee; + border: 1px solid #555; + border-radius: 3px; + user-select: none; +} + +.actions > div:hover { + background-color: #444; + color: white; +} + +.infoContainer { + display: flex; + flex-direction: column; + align-items: center; +} + +.infoContainer > div { + margin: 2px; + text-align: center; +} + +.infoContainer li { + margin: 5px 0px; +} + +.infoHeader { + color: white; + font-size: 38px; + font-weight: bold; +} + +.infoReadButton { + cursor: pointer; + padding: 10px 30px; + + border: 1px solid #444; + border-radius: 3px; +} + +.infoReadButton:hover { + background-color: #444; +} diff --git a/src/components/LoadingIndicator.js b/src/components/LoadingIndicator.js index 1212c1c..d197376 100644 --- a/src/components/LoadingIndicator.js +++ b/src/components/LoadingIndicator.js @@ -1,13 +1,11 @@ -import React, { PureComponent } from 'react' +import React from 'react' -class LoadingIndicator extends PureComponent { - render () { - return ( -
- Loading... -
- ) - } +import styles from './LoadingIndicator.module.css' + +export default function LoadingIndicator() { + return ( +
+
+
+ ) } - -export default LoadingIndicator diff --git a/src/components/LoadingIndicator.module.css b/src/components/LoadingIndicator.module.css new file mode 100644 index 0000000..4638be8 --- /dev/null +++ b/src/components/LoadingIndicator.module.css @@ -0,0 +1,24 @@ +.load { + border: 4px solid #f3f3f3; + border-top: 4px solid #99f; + border-radius: 50%; + width: 20px; + height: 20px; + animation: spin 2s linear infinite; + + margin: 10px; +} + +@keyframes spin { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} + +.loadContainer { + display: flex; + justify-content: center; +} diff --git a/src/components/Question.js b/src/components/Question.js index 242c8e8..00984ab 100644 --- a/src/components/Question.js +++ b/src/components/Question.js @@ -1,78 +1,121 @@ -import React, { PureComponent } from 'react' +import React from 'react' import styles from './question.module.css' -class Question extends PureComponent { - render () { - const { subjInd, question, onChange, deleteQuestion } = this.props +const overflowLength = 140 - let qdata = question.data - if (typeof qdata === 'object' && qdata.type === 'simple') { - qdata = '' - } - if (qdata) { - try { - qdata = JSON.stringify(qdata) - } catch (e) {} - } +export default function Question({ question, onChange, index }) { + // FIXME: focus change when input changes to textarea + const possibleAnswers = + question.possibleAnswers || question.data.possibleAnswers - const qChange = (e) => { - onChange(subjInd, question.ind, { - ...question, - [e.target.name]: e.target.value - }) - } - - const qDataChange = (e) => { - try { - let newData = JSON.parse(e.target.value) - onChange(subjInd, question.ind, { - ...question, - data: newData - }) - } catch (e) { - console.log('invalid JSON') - } - } - - return ( -
-
- -
-
- -
-
- - { deleteQuestion(subjInd, question.ind) }} - > - Delete question - -
-
- ) - } + return ( +
+ {question.Q && question.Q.length > overflowLength ? ( +