From 77943f248166c286bcb6dff826bc2b4e1752fd56 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 1 Apr 2021 16:15:20 +0200 Subject: search page sorted by date --- pages/search.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'pages') diff --git a/pages/search.tsx b/pages/search.tsx index a0eb32c..3eb46ab 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -54,7 +54,7 @@ function Posts(props: { posts: Array }) { export default function SearchPage() { var [posts, setPosts] = useState({ posts: [], valid_tags: [] }); - var [query, setQuery] = useState(""); + var [query, setQuery] = useState("-"); var [visiblePosts, setVisiblePosts] = useState>([]); var fuse = new Fuse(posts.posts, { @@ -73,10 +73,12 @@ export default function SearchPage() { var query = new URLSearchParams(window.location.search).get("q") || ""; if(query) (document.getElementById("searchInput") as HTMLInputElement).value = query; - setQuery(query); var posts = await fetch("/posts.json"); - setPosts(await posts.json()); + var postsJson: PostsInfo = await posts.json(); + postsJson.posts = postsJson.posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) + setPosts(postsJson); + setQuery(query); })()}, []); useEffect(() => { -- cgit v1.2.3