Skip to content

Commit 4cbab2b

Browse files
committed
feat: refactor search page
1 parent bd51476 commit 4cbab2b

File tree

3 files changed

+42
-43
lines changed

3 files changed

+42
-43
lines changed

apps/web/@/messages/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@
119119
"order_by_name": "Name",
120120
"order_by_size": "Size",
121121
"order_by_type": "Type",
122-
"order_by_uploaded_at": "Uploaded at"
122+
"order_by_uploaded_at": "Uploaded at",
123+
"search_results_for": "Search results for"
123124
},
124125
"uploads": {
125126
"asset_management": "Asset Management",

apps/web/@/molecules/posts/post-list/index.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import React, { useCallback, useState } from "react"
44
import { useParams } from "next/navigation"
55

6-
import { getPosts, TPostItem } from "database"
6+
import { getPosts, TGetPostsRequest, TPostItem } from "database"
77

88
import InfiniteScroll from "@/molecules/infinite-scroll"
99

1010
import PostItem from "../post-item"
1111

12-
export default function PostList() {
12+
export type TPostListProps = {
13+
getPostParams?: TGetPostsRequest
14+
}
15+
16+
export default function PostList({ getPostParams = {} }: TPostListProps) {
1317
const searchParams = useParams()
1418
const [isLoading, setIsLoading] = useState(false)
1519
const [posts, setPosts] = useState<TPostItem[]>([])
@@ -21,6 +25,7 @@ export default function PostList() {
2125

2226
setIsLoading(true)
2327
const { data } = await getPosts({
28+
...getPostParams,
2429
...searchParams,
2530
page: page.toString(),
2631
})
@@ -32,16 +37,18 @@ export default function PostList() {
3237
}, [searchParams, page])
3338

3439
return (
35-
<InfiniteScroll
36-
loading={isLoading}
37-
nextPage={loadPosts}
38-
>
39-
{posts?.map((post) => (
40-
<PostItem
41-
key={post.id}
42-
post={post}
43-
/>
44-
))}
45-
</InfiniteScroll>
40+
<div className="mt-4">
41+
<InfiniteScroll
42+
loading={isLoading}
43+
nextPage={loadPosts}
44+
>
45+
{posts?.map((post) => (
46+
<PostItem
47+
key={post.id}
48+
post={post}
49+
/>
50+
))}
51+
</InfiniteScroll>
52+
</div>
4653
)
4754
}
Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,43 @@
11
import { Metadata } from "next"
22

3-
import { getPosts } from "database"
3+
import { getTranslations } from "next-intl/server"
4+
import { Typography } from "ui"
45

56
import Filter from "@/molecules/home/filter"
67
import SearchBar from "@/molecules/nav/search-bar"
7-
import NoItemFounded from "@/molecules/no-item-founded"
8-
import PostItem from "@/molecules/posts/post-item"
8+
import PostList from "@/molecules/posts/post-list"
99

1010
export async function generateMetadata({ searchParams }): Promise<Metadata> {
1111
return {
12-
title: `${searchParams?.search} - Search result`,
13-
description: `Search result for "${searchParams?.search}`,
12+
title: `${searchParams?.search} - Search results`,
13+
description: `Search results for "${searchParams?.search}"`,
1414
}
1515
}
1616

17-
// TODO: Hight light matching
18-
// TODO: Load more
1917
export default async function Page({ searchParams }) {
20-
// TODO: Add pagination
21-
const posts = await getPosts({
22-
searchParams,
18+
const t = await getTranslations({
19+
namespace: "common",
2320
})
2421

2522
return (
26-
<div className="">
27-
<h1 className="flex-1 text-xl font-extrabold">
28-
{`${posts?.data?.total} results for`}
29-
<span className="px-2 text-2xl">{`"${searchParams?.search}"`}</span>
30-
</h1>
23+
<div>
24+
<Typography
25+
variant="h1"
26+
className="flex-1 text-xl font-extrabold lg:text-2xl"
27+
>
28+
{t("search_results_for")}
29+
<strong className="px-2 text-xl lg:text-2xl">{`"${searchParams?.search}"`}</strong>
30+
</Typography>
3131

3232
<SearchBar />
3333

3434
<Filter className="mt-3" />
3535

36-
{posts?.data?.data?.length === 0 ? (
37-
<NoItemFounded />
38-
) : (
39-
<div className="mt-4">
40-
<div className="mt-4">
41-
{posts?.data?.data?.map((post) => (
42-
<PostItem
43-
key={post.id}
44-
post={post}
45-
/>
46-
))}
47-
</div>
48-
</div>
49-
)}
36+
<PostList
37+
getPostParams={{
38+
search: searchParams?.search,
39+
}}
40+
/>
5041
</div>
5142
)
5243
}

0 commit comments

Comments
 (0)