update packages and search fix
This commit is contained in:
1 parent
d8161be401
commit
a311ef72d3
8 files changed
+838
-2386
No files matched your search
@@ -38,13 +38,16 @@ const PostQuery = ({
|
||||
|
||||
const [posts, setPosts] = useState([] as IPost[])
|
||||
const [count, setCount] = useState(0)
|
||||
const [isLoading, setLoading] = useState(true)
|
||||
const [isLoading, setLoading] = useState(router.asPath.includes('?'))
|
||||
|
||||
useEffect(() => {
|
||||
if (router.query.q) {
|
||||
const u = new URL(location.href)
|
||||
const q = u.searchParams.get('q')
|
||||
|
||||
if (q) {
|
||||
const querystrings: string[] = []
|
||||
for (const [k, v] of Object.entries({
|
||||
q: router.query.q,
|
||||
q,
|
||||
page: router.query.page,
|
||||
tag: router.query.tag
|
||||
})) {
|
||||
@@ -58,20 +61,24 @@ const PostQuery = ({
|
||||
.then(({ result, count }) => {
|
||||
setPosts(result)
|
||||
setCount(count)
|
||||
|
||||
setLoading(false)
|
||||
})
|
||||
} else {
|
||||
setPosts(defaults.posts)
|
||||
setCount(defaults.count)
|
||||
}
|
||||
|
||||
setLoading(false)
|
||||
setLoading(false)
|
||||
}
|
||||
}, [router.query.q, router.query.page, router.query.tag])
|
||||
|
||||
const totalPages = Math.ceil(count / 5)
|
||||
|
||||
return (
|
||||
return isLoading ? (
|
||||
<div>Loading...</div>
|
||||
) : (
|
||||
<article>
|
||||
{isLoading ? null : posts.length ? (
|
||||
{posts.length ? (
|
||||
posts.map((p) => <PostTeaser post={p} key={p.path} />)
|
||||
) : (
|
||||
<p>No posts found.</p>
|
||||
|
||||
Reference in new issue
Block a user