mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Question searcher / subject browser improving
This commit is contained in:
parent
748a2d826c
commit
e317ac08b7
6 changed files with 179 additions and 3 deletions
61
src/pages/subjectBrowser.js
Normal file
61
src/pages/subjectBrowser.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
import React, { useState, useEffect } from 'react'
|
||||
import fetch from 'unfetch'
|
||||
|
||||
import LoadingIndicator from '../components/LoadingIndicator.js'
|
||||
import Subject from '../components/Subject.js'
|
||||
import SubjectSelector from '../components/SubjectSelector.js'
|
||||
|
||||
import constants from '../constants.json'
|
||||
|
||||
export default function AllQuestions (props) {
|
||||
const [data, setData] = useState(null)
|
||||
const [activeSubjName, setActiveSubjName] = useState('')
|
||||
const [searchTerm, setSearchTerm] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
console.info('Fetching data')
|
||||
fetch(`${constants.apiUrl}data.json`)
|
||||
.then((resp) => {
|
||||
return resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
setData(data)
|
||||
})
|
||||
}, [])
|
||||
|
||||
if (data) {
|
||||
let currSubj = data.Subjects.find((subj) => {
|
||||
return subj.Name === activeSubjName
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<input
|
||||
placeholder='Keresés...'
|
||||
className='searchBar'
|
||||
type='text'
|
||||
value={searchTerm}
|
||||
onChange={(e) => { setSearchTerm(e.target.value) }}
|
||||
/>
|
||||
</div>
|
||||
<SubjectSelector
|
||||
data={data}
|
||||
activeSubjName={activeSubjName}
|
||||
searchTerm={searchTerm}
|
||||
onSubjSelect={(subjName) => { setActiveSubjName(subjName) }}
|
||||
/>
|
||||
<hr />
|
||||
<div>
|
||||
<Subject
|
||||
subj={currSubj}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<LoadingIndicator />
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue