mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Added git links to todo sidebar
This commit is contained in:
parent
91e4e24ff7
commit
57f0730f3e
10 changed files with 329 additions and 90 deletions
src/pages
|
@ -6,22 +6,76 @@ import QuestionSearchResult from '../components/QuestionSearchResult.js'
|
|||
|
||||
import styles from './allQuestions.module.css'
|
||||
|
||||
export default function AllQuestions({ router, getData }) {
|
||||
import constants from '../constants.json'
|
||||
|
||||
function mergeData(data) {
|
||||
return data.reduce((acc, db) => {
|
||||
return [
|
||||
...acc,
|
||||
...db.data.map((subj) => {
|
||||
return {
|
||||
...subj,
|
||||
Name: `${subj.Name} (${db.dbName})`,
|
||||
}
|
||||
}),
|
||||
]
|
||||
}, [])
|
||||
}
|
||||
|
||||
function fetchData(db) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(`${constants.apiUrl}${db.path}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((resp) => {
|
||||
resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
resolve({
|
||||
dbName: db.name,
|
||||
data: data,
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function fetchDbs() {
|
||||
return new Promise((resolve) => {
|
||||
console.info('Fetching data')
|
||||
fetch(`${constants.apiUrl}getDbs`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((resp) => {
|
||||
return resp.json()
|
||||
})
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default function AllQuestions({ router }) {
|
||||
const [data, setData] = useState(null)
|
||||
const [dbs, setDbs] = useState(null)
|
||||
const [searchTerm, setSearchTerm] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
getData().then((result) => {
|
||||
setData(result)
|
||||
|
||||
router.replace(`${router.asPath.replace('.html', '')}`, undefined, {
|
||||
shallow: true,
|
||||
})
|
||||
const querySearch = router.query.question
|
||||
? decodeURIComponent(router.query.question)
|
||||
: ''
|
||||
setSearchTerm(querySearch)
|
||||
router.replace(`${router.asPath.replace('.html', '')}`, undefined, {
|
||||
shallow: true,
|
||||
})
|
||||
const querySearch = router.query.question
|
||||
? decodeURIComponent(router.query.question)
|
||||
: ''
|
||||
|
||||
fetchDbs().then((res) => {
|
||||
setDbs(res)
|
||||
console.log(res)
|
||||
})
|
||||
// fetchData().then((result) => {
|
||||
// setData(result)
|
||||
|
||||
// setSearchTerm(querySearch)
|
||||
// })
|
||||
}, [])
|
||||
|
||||
return (
|
||||
|
@ -29,6 +83,29 @@ export default function AllQuestions({ router, getData }) {
|
|||
<Head>
|
||||
<title>Qmining - Kérdés keresés | Frylabs.net</title>
|
||||
</Head>
|
||||
{dbs ? (
|
||||
<>
|
||||
<select
|
||||
onChange={(e) => {
|
||||
console.log(e.target.value)
|
||||
}}
|
||||
>
|
||||
<option value={'none'} key={'none'}>
|
||||
{'...'}
|
||||
</option>
|
||||
{dbs.map((db) => {
|
||||
return (
|
||||
<option value={db.path} key={db.path}>
|
||||
{db.name}
|
||||
</option>
|
||||
)
|
||||
})}
|
||||
<option value={'all'} key={'all'}>
|
||||
{'All'}
|
||||
</option>
|
||||
</select>
|
||||
</>
|
||||
) : null}
|
||||
{data ? (
|
||||
<>
|
||||
<div className={styles.searchContainer}>
|
||||
|
@ -38,11 +115,11 @@ export default function AllQuestions({ router, getData }) {
|
|||
className={styles.searchBar}
|
||||
type="text"
|
||||
value={searchTerm}
|
||||
onChange={(e) => {
|
||||
setSearchTerm(e.target.value)
|
||||
onChange={(event) => {
|
||||
setSearchTerm(event.target.value)
|
||||
router.replace(
|
||||
`${router.pathname}${e.target.value &&
|
||||
'?question='}${encodeURIComponent(e.target.value)}`,
|
||||
`${router.pathname}${event.target.value &&
|
||||
'?question='}${encodeURIComponent(event.target.value)}`,
|
||||
undefined,
|
||||
{ shallow: true }
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue