From 1f90e62ac3b2c748ee3c9af57ab36a3576e4004e Mon Sep 17 00:00:00 2001 From: mrfry Date: Tue, 23 Mar 2021 20:00:52 +0100 Subject: [PATCH] Changed lotsa stuff 2 --- src/components/QuestionSearchResult.js | 125 ++++++++++++------------- src/components/layout.js | 4 +- src/defaultStyles.css | 8 +- src/pages/allQuestions.js | 33 ++++--- src/pages/allQuestions.module.css | 4 - src/pages/contact.js | 68 +------------- src/pages/contact.module.css | 13 --- src/pages/contribute.js | 2 + src/pages/pwRequest.js | 15 +-- src/pages/script.js | 37 ++++---- 10 files changed, 119 insertions(+), 190 deletions(-) diff --git a/src/components/QuestionSearchResult.js b/src/components/QuestionSearchResult.js index 12f7ab8..b661d3d 100644 --- a/src/components/QuestionSearchResult.js +++ b/src/components/QuestionSearchResult.js @@ -1,4 +1,4 @@ -import React, { PureComponent } from 'react' +import React from 'react' import Questions from './Questions.js' @@ -8,75 +8,74 @@ const countReducer = (acc, subj) => { return acc + subj.Questions.length } -class QuestionSearchResult extends PureComponent { - render() { - const { data, searchTerm } = this.props +export default function QuestionSearchResult({ data, searchTerm }) { + let subjs = [] + let results = -1 - let subjs = [] - let results = -1 - - if (searchTerm) { - subjs = data.reduce((acc, subj) => { - const resultQuestions = subj.Questions.reduce((qacc, question) => { - const keys = ['Q', 'A', 'data'] - keys.some((key) => { - if (typeof question[key] !== 'string') { - return false - } - if ( - question[key] && - question[key].toLowerCase().includes(searchTerm.toLowerCase()) - ) { - qacc.push(question) - return true - } - }) - return qacc - }, []) - if (resultQuestions.length > 0) { - acc.push({ - Name: subj.Name, - Questions: resultQuestions, - }) - } - return acc + if (searchTerm) { + subjs = data.reduce((acc, subj) => { + const resultQuestions = subj.Questions.reduce((qacc, question) => { + const keys = ['Q', 'A', 'data'] + keys.some((key) => { + if (typeof question[key] !== 'string') { + return false + } + if ( + question[key] && + question[key].toLowerCase().includes(searchTerm.toLowerCase()) + ) { + qacc.push(question) + return true + } + }) + return qacc }, []) - results = subjs.reduce(countReducer, 0) - } else { - results = data.reduce(countReducer, 0) - } + if (resultQuestions.length > 0) { + acc.push({ + Name: subj.Name, + Questions: resultQuestions, + }) + } + return acc + }, []) + results = subjs.reduce(countReducer, 0) + } else { + results = data.reduce(countReducer, 0) + } - const renderCount = () => { - return ( + const renderCount = () => { + return ( +
-
- {searchTerm ? '' : 'Kezdj el írni kereséshez! '} - {`${results} találat, ${subjs.length} tárgyból`} -
- {results === 0 && ( -
- { - 'Pontos egyezést keres a kereső, próbálj kisebb részletre keresni' - } -
- )} + {searchTerm ? '' : 'Kezdj el írni kereséshez! '} + {`${results} találat, ${subjs.length || data.length} tárgyból`}
- ) - } + {results === 0 && ( +
+ {'Pontos egyezést keres a kereső, próbálj kisebb részletre keresni'} +
+ )} +
+ ) + } - if (results > constants.maxQuestionsToRender) { - return renderCount() - } else { - return ( + if (results > constants.maxQuestionsToRender) { + return ( +
+ {renderCount()} + {searchTerm ? ( +
Szűkítsd a keresést találatok megjelenítéséhez!
+ ) : null} +
+ ) + } else { + return ( +
+
{renderCount()}
-
{renderCount()}
-
- -
+
- ) - } +
+ ) } } - -export default QuestionSearchResult diff --git a/src/components/layout.js b/src/components/layout.js index 66204f8..f0c97f9 100644 --- a/src/components/layout.js +++ b/src/components/layout.js @@ -192,13 +192,13 @@ export default function Layout({ ) : null} {donateShowing ? ( - { setDonateShowing(false) }} >
hi
-
+ ) : null} {showMotdModal ? ( Tárgyak -
- { - if (selectedDb === 'all') { - window.open(`${constants.apiUrl}allqr.txt`, '_blank') - } else { - window.open( - `${constants.apiUrl}allqr.txt?db=${selectedDb}`, - '_blank' - ) - } - }} - className={styles.button} - > - {'Kérdések letöltése'} - -
+ { + if (selectedDb === 'all') { + window.open(`${constants.apiUrl}allqr.txt`, '_blank') + } else { + window.open( + `${constants.apiUrl}allqr.txt?db=${selectedDb}`, + '_blank' + ) + } + }} + > + {'Kérdések letöltése'} + + {fetchingData ? ( diff --git a/src/pages/allQuestions.module.css b/src/pages/allQuestions.module.css index e60fd57..e2dffe6 100644 --- a/src/pages/allQuestions.module.css +++ b/src/pages/allQuestions.module.css @@ -11,7 +11,3 @@ cursor: pointer; border: none; } - -.activeTypeSelector { - background-color: #444; -} diff --git a/src/pages/contact.js b/src/pages/contact.js index 0624408..97f1809 100644 --- a/src/pages/contact.js +++ b/src/pages/contact.js @@ -1,8 +1,9 @@ -import React, { useState } from 'react' +import React from 'react' import Head from 'next/head' +import FeedbackArea from '../components/feedbackArea' + import styles from './contact.module.css' -import constants from '../constants.json' const contactMethods = { irc: { @@ -21,74 +22,13 @@ const contactMethods = { }, } -function submitFeedback(msg) { - return new Promise((resolve) => { - fetch(constants.apiUrl + 'postfeedback', { - method: 'POST', - credentials: 'include', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - newTask: msg, - from: 'contribute', - }), - }) - .then((resp) => { - return resp.json() - }) - .then((resp) => { - if (resp.success) { - resolve() - } else { - alert('Hiba küldés közben') - } - }) - .catch((err) => { - alert('Hiba küldés közben') - console.error(err) - }) - }) -} - export default function Contact() { - const [feedback, setFeedback] = useState('') - - const feedbackArea = () => { - return ( -
-