mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Initial commit
This commit is contained in:
commit
d0a48513e9
28 changed files with 724 additions and 0 deletions
100
src/components/AllQuestions/AllQuestions.js
Normal file
100
src/components/AllQuestions/AllQuestions.js
Normal file
|
@ -0,0 +1,100 @@
|
|||
import React, { PureComponent } from 'react'
|
||||
|
||||
import LoadingIndicator from '../LoadingIndicator'
|
||||
import Subject from '../../components/Subject'
|
||||
|
||||
import constants from '../../constants.json'
|
||||
import './AllQuestions.css'
|
||||
|
||||
class AllQuestions extends PureComponent {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
loaded: false,
|
||||
activeSubjName: '',
|
||||
searchTerm: ''
|
||||
}
|
||||
|
||||
console.info('Fetching data')
|
||||
fetch(`${constants.serverUrl}data.json`) // eslint-disable-line
|
||||
.then((resp) => {
|
||||
return resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
this.data = data
|
||||
this.setState({
|
||||
loaded: true
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
onSubjSelect (name) {
|
||||
this.setState({
|
||||
activeSubjName: name
|
||||
})
|
||||
}
|
||||
|
||||
searchBarOnChange (e) {
|
||||
let text = e.target.value
|
||||
this.setState({
|
||||
searchTerm: text
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
const { loaded, activeSubjName, searchTerm } = this.state
|
||||
|
||||
if (loaded) {
|
||||
let currSubj = this.data.Subjects.find((subj) => {
|
||||
return subj.Name === activeSubjName
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<input
|
||||
placeholder='Keresés...'
|
||||
className='searchBar'
|
||||
type='text'
|
||||
value={searchTerm}
|
||||
onChange={this.searchBarOnChange.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
<div className='subjectSelector'>
|
||||
{this.data.Subjects.map((subj, i) => {
|
||||
if (!subj.Name.toLowerCase().includes(searchTerm.toLowerCase())) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={activeSubjName === subj.Name
|
||||
? 'subjItem activeSubjItem'
|
||||
: 'subjItem'
|
||||
}
|
||||
key={i}
|
||||
onClick={() => this.onSubjSelect(subj.Name)}
|
||||
>
|
||||
{subj.Name}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<hr />
|
||||
<div>
|
||||
<Subject
|
||||
subj={currSubj}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<LoadingIndicator />
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default AllQuestions
|
Loading…
Add table
Add a link
Reference in a new issue