diff --git a/src/app/(main)/berita/search/page.tsx b/src/app/(main)/berita/search/page.tsx index 9cc8740c..9217141a 100644 --- a/src/app/(main)/berita/search/page.tsx +++ b/src/app/(main)/berita/search/page.tsx @@ -1,4 +1,4 @@ -import { NewsFigure } from "@/app/_components/global/NewsFigure"; +import { NewsSearchFigure } from "@/app/_components/global/NewsFigure"; import { H2 } from "@/app/_components/global/Text"; import { SmallSectionWrapper } from "@/app/_components/global/Wrapper"; import { PostWithTagsAndUser } from "@/types/entityRelations"; @@ -6,6 +6,7 @@ import { findPosts } from "@/utils/database/post.query"; import GoBack from "../[slug]/_components/BackButton"; import { SearchBar } from "../_components/SearchBar"; +import { redirect } from "next/navigation"; export default async function Search({ searchParams, @@ -29,10 +30,12 @@ export default async function Search({ Menampilkan hasil pencarian untuk " {searchParams.q?.toString() ?? ""}" -
- {posts.map((post) => ( - - ))} +
+ {posts.length !== 0 + ? posts.map((post) => ( + + )) + : redirect("/berita")}
diff --git a/src/app/_components/global/NewsFigure.tsx b/src/app/_components/global/NewsFigure.tsx index 17586d0a..48b9ecde 100644 --- a/src/app/_components/global/NewsFigure.tsx +++ b/src/app/_components/global/NewsFigure.tsx @@ -73,3 +73,60 @@ export function NewsFigure({ post }: Readonly<{ post: PostWithTagsAndUser }>) { ); } +export function NewsSearchFigure({ + post, +}: Readonly<{ post: PostWithTagsAndUser }>) { + return ( +
+
+ {post.slug} +
+
+
+
+ {post.tags.map((tag) => ( + + ))} +
+ +
+ + {post.title.length > 52 + ? post.title.slice(0, 48) + "..." + : post.title} + +
+ +
+
+
+ {post.user.name + + {trimName(post.user.name)} + +
+ + {post.published_at && stringifyDate(post.published_at)} + +
+
+
+ ); +}