fix searching

This commit is contained in:
polv committed 2020-12-18 09:37:43 +07:00
1 parent 25585aa3da
commit 43edfb60d4
10 files changed
+126 -102

No files matched your search

+6 -3
View File
@@ -36,8 +36,9 @@ const PostQuery = ({
return pathname
}
const [posts, setPosts] = useState(defaults.posts)
const [count, setCount] = useState(defaults.count)
const [posts, setPosts] = useState([] as IPost[])
const [count, setCount] = useState(0)
const [isLoading, setLoading] = useState(true)
useEffect(() => {
if (router.query.q) {
@@ -62,13 +63,15 @@ const PostQuery = ({
setPosts(defaults.posts)
setCount(defaults.count)
}
setLoading(false)
}, [router.query.q, router.query.page, router.query.tag])
const totalPages = Math.ceil(count / 5)
return (
<article>
{posts.length ? (
{isLoading ? null : posts.length ? (
posts.map((p) => <PostTeaser post={p} key={p.path} />)
) : (
<p>No posts found.</p>