mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Search term in query for all questions
This commit is contained in:
parent
9aa0c111ce
commit
36a564498b
2 changed files with 20 additions and 15 deletions
|
@ -3,10 +3,10 @@
|
||||||
import '../defaultStyles.css'
|
import '../defaultStyles.css'
|
||||||
import Layout from '../components/layout'
|
import Layout from '../components/layout'
|
||||||
|
|
||||||
function MyApp ({ Component, pageProps, router }) {
|
function MyApp({ Component, pageProps, router }) {
|
||||||
return (
|
return (
|
||||||
<Layout route={router.route}>
|
<Layout route={router.route}>
|
||||||
<Component {...pageProps} />
|
<Component {...pageProps} router={router} />
|
||||||
</Layout>
|
</Layout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
|
import Link from 'next/link'
|
||||||
import fetch from 'unfetch'
|
import fetch from 'unfetch'
|
||||||
|
|
||||||
import LoadingIndicator from '../components/LoadingIndicator.js'
|
import LoadingIndicator from '../components/LoadingIndicator.js'
|
||||||
|
@ -7,13 +8,13 @@ import QuestionSearchResult from '../components/QuestionSearchResult.js'
|
||||||
import styles from './allQuestions.module.css'
|
import styles from './allQuestions.module.css'
|
||||||
import constants from '../constants.json'
|
import constants from '../constants.json'
|
||||||
|
|
||||||
export default function AllQuestions (props) {
|
export default function AllQuestions({ router }) {
|
||||||
const [data, setData] = useState(null)
|
const [data, setData] = useState(null)
|
||||||
const [searchTerm, setSearchTerm] = useState('')
|
const [searchTerm, setSearchTerm] = useState('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${constants.apiUrl}data.json`, {
|
fetch(`${constants.apiUrl}data.json`, {
|
||||||
credentials: 'include'
|
credentials: 'include',
|
||||||
})
|
})
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
return resp.json()
|
return resp.json()
|
||||||
|
@ -21,6 +22,7 @@ export default function AllQuestions (props) {
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setData(data)
|
setData(data)
|
||||||
})
|
})
|
||||||
|
setSearchTerm(router.query.q ? decodeURIComponent(router.query.q) : '')
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -28,11 +30,19 @@ export default function AllQuestions (props) {
|
||||||
<div>
|
<div>
|
||||||
<div className={styles.searchContainer}>
|
<div className={styles.searchContainer}>
|
||||||
<input
|
<input
|
||||||
placeholder='Keresés...'
|
placeholder="Keresés..."
|
||||||
className={styles.searchBar}
|
className={styles.searchBar}
|
||||||
type='text'
|
type="text"
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onChange={(e) => { setSearchTerm(e.target.value) }}
|
onChange={(e) => {
|
||||||
|
setSearchTerm(e.target.value)
|
||||||
|
router.replace(
|
||||||
|
`${router.pathname}${e.target.value &&
|
||||||
|
'?q='}${encodeURIComponent(e.target.value)}`,
|
||||||
|
undefined,
|
||||||
|
{ shallow: true }
|
||||||
|
)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -40,21 +50,16 @@ export default function AllQuestions (props) {
|
||||||
}}
|
}}
|
||||||
className={styles.clearButton}
|
className={styles.clearButton}
|
||||||
>
|
>
|
||||||
X
|
X
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
<div>
|
<div>
|
||||||
<QuestionSearchResult
|
<QuestionSearchResult data={data} searchTerm={searchTerm} />
|
||||||
data={data}
|
|
||||||
searchTerm={searchTerm}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return <LoadingIndicator />
|
||||||
<LoadingIndicator />
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue