mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Changed lotsa stuff 2
This commit is contained in:
parent
7bb7b919ae
commit
1f90e62ac3
10 changed files with 119 additions and 190 deletions
|
@ -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 (
|
||||
<div>
|
||||
<div>
|
||||
<div>
|
||||
{searchTerm ? '' : 'Kezdj el írni kereséshez! '}
|
||||
{`${results} találat, ${subjs.length} tárgyból`}
|
||||
</div>
|
||||
{results === 0 && (
|
||||
<div>
|
||||
{
|
||||
'Pontos egyezést keres a kereső, próbálj kisebb részletre keresni'
|
||||
}
|
||||
</div>
|
||||
)}
|
||||
{searchTerm ? '' : 'Kezdj el írni kereséshez! '}
|
||||
{`${results} találat, ${subjs.length || data.length} tárgyból`}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
{results === 0 && (
|
||||
<div>
|
||||
{'Pontos egyezést keres a kereső, próbálj kisebb részletre keresni'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (results > constants.maxQuestionsToRender) {
|
||||
return renderCount()
|
||||
} else {
|
||||
return (
|
||||
if (results > constants.maxQuestionsToRender) {
|
||||
return (
|
||||
<div>
|
||||
{renderCount()}
|
||||
{searchTerm ? (
|
||||
<div>Szűkítsd a keresést találatok megjelenítéséhez!</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
<div>{renderCount()}</div>
|
||||
<div>
|
||||
<div>{renderCount()}</div>
|
||||
<div>
|
||||
<Questions subjs={subjs} />
|
||||
</div>
|
||||
<Questions subjs={subjs} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default QuestionSearchResult
|
||||
|
|
|
@ -192,13 +192,13 @@ export default function Layout({
|
|||
) : null}
|
||||
</div>
|
||||
{donateShowing ? (
|
||||
<Layout
|
||||
<Modal
|
||||
closeClick={() => {
|
||||
setDonateShowing(false)
|
||||
}}
|
||||
>
|
||||
<div>hi</div>
|
||||
</Layout>
|
||||
</Modal>
|
||||
) : null}
|
||||
{showMotdModal ? (
|
||||
<Modal
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue