diff --git a/app/news/detail/[id]/page.tsx b/app/news/detail/[id]/page.tsx index d4b16a1..e1176b2 100644 --- a/app/news/detail/[id]/page.tsx +++ b/app/news/detail/[id]/page.tsx @@ -1,20 +1,34 @@ -"use client"; import { HumasLayout } from "@/components/layout/humas-layout"; import DetailPage from "@/components/main/detail/new-detail"; -import React, { useEffect, useState } from "react"; +import { getArticleById } from "@/service/article"; +import { Metadata } from "next"; -export default function NewsPage() { - const [hasMounted, setHasMounted] = useState(false); +type Props = { + params: { id: string }; +}; - useEffect(() => { - setHasMounted(true); - }, []); +export async function generateMetadata({ params }: Props): Promise { + const res = await getArticleById(params.id?.split("-")[0]); + const article = res?.data?.data; - // Render - if (!hasMounted) return null; + return { + title: article.title, + description: article.description, + openGraph: { + title: article.title, + description: article.description, + images: [article.thumbnailUrl], + }, + }; +} + +export default async function NewsPage({ params }: Props) { + const articleId = params.id?.split("-")[0]; + const res = await getArticleById(articleId); + const article = res?.data?.data; return ( - + ); } diff --git a/components/main/detail/new-detail.tsx b/components/main/detail/new-detail.tsx index caabdf6..222227c 100644 --- a/components/main/detail/new-detail.tsx +++ b/components/main/detail/new-detail.tsx @@ -16,7 +16,7 @@ import Head from "next/head"; const token = Cookies.get("access_token"); const uid = Cookies.get("uie"); -export default function NewsDetailPage() { +export default function NewsDetailPage(props: { datas: any }) { const params = useParams(); const id: any = params?.id; const pathname = usePathname(); @@ -24,7 +24,7 @@ export default function NewsDetailPage() { const [articles, setArticles] = useState([]); useEffect(() => { - initFetch(); + // initFetch(); getArticles(); sendActivity(); }, []); @@ -57,7 +57,7 @@ export default function NewsDetailPage() { }; return ( <> - {" "} + {/* {" "} {detailArticle?.title} @@ -72,7 +72,7 @@ export default function NewsDetailPage() { - + */}
@@ -83,7 +83,7 @@ export default function NewsDetailPage() {

Berita

- +