From 21bd0c01771cce8f693a32a0ae5d2f5fda4d55fb Mon Sep 17 00:00:00 2001 From: mrfry Date: Sun, 10 Jan 2021 15:47:56 +0100 Subject: [PATCH] Removed question adding --- src/data/tabs.json | 4 - src/pages/addQuestion.js | 323 ------------------------------- src/pages/addQuestion.module.css | 116 ----------- 3 files changed, 443 deletions(-) delete mode 100644 src/pages/addQuestion.js delete mode 100644 src/pages/addQuestion.module.css diff --git a/src/data/tabs.json b/src/data/tabs.json index 6b374b1..3fb334a 100644 --- a/src/data/tabs.json +++ b/src/data/tabs.json @@ -11,10 +11,6 @@ "href": "/allQuestions", "text": "Kérdések és tárgyak" }, - "addQuestion": { - "href": "/addQuestion", - "text": "Kérdés beküldés" - }, "pwRequest": { "href": "/pwRequest", "text": "Jelszó kérés" diff --git a/src/pages/addQuestion.js b/src/pages/addQuestion.js deleted file mode 100644 index 0f1e1cf..0000000 --- a/src/pages/addQuestion.js +++ /dev/null @@ -1,323 +0,0 @@ -import React, { useState, useEffect } from 'react' -import fetch from 'unfetch' -import Head from 'next/head' - -import LoadingIndicator from '../components/LoadingIndicator.js' - -import styles from './addQuestion.module.css' -import constants from '../constants.json' - -const getDefaultQuestion = () => { - return { - Q: '', - A: '', - data: { type: 'simple' }, - } -} - -export default function AddQuestion() { - const [form, setForm] = useState({ quiz: [getDefaultQuestion()] }) - const [subjects, setSubjects] = useState(undefined) - const [isSubmitting, setIsSubmitting] = useState(false) - const [isNewSubj, setIsNewSubj] = useState(false) - - useEffect(() => { - console.info('Fetching subject names') - fetch(`${constants.apiUrl}dataCount?detailed=true`, { - credentials: 'include', - }) - .then((resp) => { - return resp.json() - }) - .then((data) => { - let res = data.reduce((acc, x) => { - return [ - ...acc, - ...x.subjs.map((subj) => { - return subj.name - }), - ] - }, []) - - res = res.sort() - setSubjects(res) - }) - }, []) - - const onChange = (newData, index) => { - let quiz = form.quiz - quiz[index] = newData - - setForm({ - ...form, - quiz: quiz, - }) - } - - const renderQuestionInput = (params) => { - const { index, onChange } = params - const currData = form.quiz[index] - const { Q, A, data } = form.quiz[index] || {} - - return ( -
-
- - onChange({ ...currData, Q: err.target.value }, index) - } - value={Q || ''} - className={styles.questionInput} - /> -
-
- - onChange({ ...currData, A: err.target.value }, index) - } - value={A || ''} - className={styles.questionInput} - /> -
-
- { - // TODO: handle JSON - // try { - // let newData = JSON.parse(e.target.value) - // onChange({ ...currData, data: newData }, index) - // } catch (e) { - // } - }} - value={JSON.stringify(data) || ''} - className={styles.questionInput} - /> - deleteQuestion(index)} - > - Kérdés törlése - -
-
-
- ) - } - - const deleteQuestion = (index) => { - let quiz = form.quiz - - quiz.splice(index, 1) - - setForm({ - ...form, - quiz: quiz, - }) - } - - const handleSubmit = async () => { - if (!form.subj) { - alert('Nem választottál ki tantárgyat!') // eslint-disable-line - return - } - let isValid = form.quiz.every((x) => { - return x.Q && x.A - }) - if (!isValid || form.quiz.length === 0) { - alert('Kérdés kitöltése kötelező!') // eslint-disable-line - return - } - - const t = document.getElementById('cid').value - let cid = '' - let version = '' - if (t) { - cid = t.split('|')[0] - version = t.split('|')[1] - } - - setIsSubmitting(true) - - const rawResponse = await fetch(constants.apiUrl + 'isAdding', { - method: 'POST', - credentials: 'include', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - ...form, - id: cid, - version: 'WEBSITE', - scriptVersion: version, - }), - }) - rawResponse - .json() - .then((resp) => { - if (resp.success) { - alert( - 'Sikeres beküldés, ' + - resp.newQuestions.reduce((acc, res) => { - return acc + res.newQuestions - }, 0) + - ' új kérdés' - ) // eslint-disable-line - setIsSubmitting(false) - } else { - alert('Hiba beküldés közben :/') // eslint-disable-line - setIsSubmitting(false) - } - }) - .catch((err) => { - alert('Hiba beküldés közben :/') // eslint-disable-line - console.log(err) - setIsSubmitting(false) - }) - } - - const renderStuff = () => { - return ( -
- {form.quiz.map((q, i) => { - return ( -
- {renderQuestionInput({ - index: i, - onChange, - })} -
- ) - })} -
-
{ - let quiz = form.quiz - quiz.push(getDefaultQuestion()) - setForm({ - ...form, - quiz: quiz, - }) - }} - > - Új kérdés -
-
- {isSubmitting ? ( -
- Kérdések feldolgozása folyamatban, ha sokat küldtél, akkor több perc - is lehet -
- ) : ( -
- -
- )} - -
- ) - } - - const renderSubjSelector = () => { - // TODO: handle if new subject - return ( -
- {isNewSubj ? ( - { - setForm({ - ...form, - subj: event.target.value, - }) - }} - /> - ) : ( - - )} - { - setIsNewSubj(!isNewSubj) - }} - > - {isNewSubj ? 'Létező tárgy ...' : 'Új tárgy ...'} - -
- ) - } - - const renderUsage = () => { - return ( - - ) - } - - return ( -
- - Qmining - Kérdés beküldés | Frylabs.net - - {subjects ? ( - <> - {renderUsage()} -
- {renderSubjSelector()} - {renderStuff()} - - ) : ( - - )} -
- ) -} diff --git a/src/pages/addQuestion.module.css b/src/pages/addQuestion.module.css deleted file mode 100644 index bba190a..0000000 --- a/src/pages/addQuestion.module.css +++ /dev/null @@ -1,116 +0,0 @@ -.questionInput { - flex-grow: 1; - font-size: 16px; - background-color: var(--background-color); - color: white; - border: none; - padding: 8px; - margin: 4px; - border: 1px solid; - border-color: var(--background-color); -} - -.questionContainer { - margin-top: 30px; - margin-bottom: 30px; - margin-right: 10px; - margin-left: 10px; -} - -.inputContainer { - width: 100%; - display: flex; -} - -.buttonContainer { - text-align: center; - width: 200px; - margin: 0 auto; - padding: 10px; -} - -.deleteButton { - display: flex; - align-items: center; - background-color: #333; - padding: 6px; - font-size: 16px; - color: white; - cursor: pointer; - border: 1px solid; - border-color: var(--background-color); -} - -.deleteButton:hover { - background-color: #666; -} - -.questionInput:hover { - border: 1px solid; -} - -.button { - cursor: pointer; - background-color: var(--text-color); - border: none; - padding: 10px 30px; - color: white; - width: 200px; -} - -.subjSelectorContainer { - width: 100%; - display: flex; -} - -.subjSelector { - flex-grow: 1; - background-color: var(--background-color); -} - -.newSubj { - display: flex; - justify-content: center; - - background-color: #333; - width: 150px; - margin: 0px 4px; - padding: 10px; - cursor: pointer; - font-size: 14px; - color: white; -} - -.newSubj:hover { - background-color: #666; -} - -.usage li { - margin: 5px; -} - -.usage { - font-size: 15px; - color: white; -} - -.issubmitting { - text-align: center; - color: white; -} - -.newQuestionButton { - display: flex; - justify-content: center; -} - -.newQuestionButton div { - background-color: #333; - color: white; - cursor: pointer; - padding: 10px 20px; -} - -.newQuestionButton div:hover { - background-color: #666; -}