Skip to content

Commit f0486ea

Browse files
Merge pull request #388 from mokletdev/development
feat: add NewsSearchFigure component and update search results layout
2 parents 4c877b5 + e86b64c commit f0486ea

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

src/app/(main)/berita/search/page.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { NewsFigure } from "@/app/_components/global/NewsFigure";
1+
import { NewsSearchFigure } from "@/app/_components/global/NewsFigure";
22
import { H2 } from "@/app/_components/global/Text";
33
import { SmallSectionWrapper } from "@/app/_components/global/Wrapper";
44
import { PostWithTagsAndUser } from "@/types/entityRelations";
55
import { findPosts } from "@/utils/database/post.query";
66

77
import GoBack from "../[slug]/_components/BackButton";
88
import { SearchBar } from "../_components/SearchBar";
9+
import { redirect } from "next/navigation";
910

1011
export default async function Search({
1112
searchParams,
@@ -29,10 +30,12 @@ export default async function Search({
2930
Menampilkan hasil pencarian untuk "
3031
{searchParams.q?.toString() ?? ""}"
3132
</H2>
32-
<div className="w-full flex gap-x-[3.18%] gap-y-[62px]">
33-
{posts.map((post) => (
34-
<NewsFigure post={post} key={post.id} />
35-
))}
33+
<div className="w-full grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-x-4 gap-y-4">
34+
{posts.length !== 0
35+
? posts.map((post) => (
36+
<NewsSearchFigure post={post} key={post.id} />
37+
))
38+
: redirect("/berita")}
3639
</div>
3740
</div>
3841
</div>

src/app/_components/global/NewsFigure.tsx

+57
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,60 @@ export function NewsFigure({ post }: Readonly<{ post: PostWithTagsAndUser }>) {
7373
</figure>
7474
);
7575
}
76+
export function NewsSearchFigure({
77+
post,
78+
}: Readonly<{ post: PostWithTagsAndUser }>) {
79+
return (
80+
<figure className="w-full">
81+
<div className="h-[200px] w-full">
82+
<Image
83+
src={post.thumbnail}
84+
alt={post.slug}
85+
unoptimized
86+
height={200}
87+
width={372}
88+
className="h-full w-full object-cover rounded-[20px]"
89+
/>
90+
</div>
91+
<div className="flex flex-col items-start justify-start gap-[26px]">
92+
<div>
93+
<div className="mb-[16px] mt-[26px] flex gap-[10px] flex-wrap">
94+
{post.tags.map((tag) => (
95+
<Tags tag={tag} key={tag.tagName} />
96+
))}
97+
</div>
98+
<Link
99+
href={"/berita/" + post.slug}
100+
className="text-black hover:text-primary-400 transition-all duration-500"
101+
>
102+
<div className="min-h-[52px]">
103+
<span className="text-[18px] md:text-xl font-bold">
104+
{post.title.length > 52
105+
? post.title.slice(0, 48) + "..."
106+
: post.title}
107+
</span>
108+
</div>
109+
</Link>
110+
</div>
111+
<div className="flex w-full justify-between">
112+
<div className="flex items-center gap-2">
113+
<Image
114+
src={post.user.user_pic}
115+
alt={post.user.name + "'s Pfp"}
116+
unoptimized
117+
height={28}
118+
width={28}
119+
className="h-7 w-7 object-cover rounded-full"
120+
/>
121+
<span className="text-base text-black">
122+
{trimName(post.user.name)}
123+
</span>
124+
</div>
125+
<span className="text-neutral-500">
126+
{post.published_at && stringifyDate(post.published_at)}
127+
</span>
128+
</div>
129+
</div>
130+
</figure>
131+
);
132+
}

0 commit comments

Comments
 (0)