From 5ada3e1433a8b73d9cee05542dc14584522c38ec Mon Sep 17 00:00:00 2001 From: Anang Yusman Date: Sun, 2 Nov 2025 14:42:38 +0800 Subject: [PATCH] update --- app/details/[slug]/page.tsx | 18 ++++++++++++ components/details/details-content.tsx | 29 +++++++++++++++----- components/landing-page/achievments.tsx | 5 ++-- components/landing-page/headers-activity.tsx | 5 ++-- components/landing-page/headers-opinion.tsx | 5 ++-- components/landing-page/headers.tsx | 3 +- components/landing-page/inspiration.tsx | 5 ++-- components/landing-page/news.tsx | 3 +- components/landing-page/opini.tsx | 3 +- components/landing-page/service.tsx | 5 ++-- components/table/article-table.tsx | 10 ++++--- service/article.ts | 7 +++++ 12 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 app/details/[slug]/page.tsx diff --git a/app/details/[slug]/page.tsx b/app/details/[slug]/page.tsx new file mode 100644 index 0000000..a13f3ca --- /dev/null +++ b/app/details/[slug]/page.tsx @@ -0,0 +1,18 @@ +import DetailContent from "@/components/details/details-content"; +import Footer from "@/components/landing-page/footer"; +import Navbar from "@/components/landing-page/navbar"; +import Image from "next/image"; + +export default function Slug() { + return ( +
+
+ +
+ +
+
+
+
+ ); +} diff --git a/components/details/details-content.tsx b/components/details/details-content.tsx index 300917c..81c5a16 100644 --- a/components/details/details-content.tsx +++ b/components/details/details-content.tsx @@ -2,7 +2,11 @@ import Image from "next/image"; import { useEffect, useState } from "react"; import Link from "next/link"; -import { getArticleById, getListArticle } from "@/service/article"; +import { + getArticleById, + getArticleBySlug, + getListArticle, +} from "@/service/article"; import { close, error, loading } from "@/config/swal"; import { useParams, usePathname } from "next/navigation"; import { CommentIcon } from "../icons/sidebar-icon"; @@ -16,6 +20,7 @@ import { postArticleComment, } from "@/service/master-user"; import { useForm } from "react-hook-form"; +import { Badge } from "../ui/badge"; type TabKey = "trending" | "comments" | "latest"; @@ -25,6 +30,7 @@ type Article = { description: string; categoryName: string; createdAt: string; + slug: string; createdByName: string; thumbnailUrl: string; categories: { @@ -54,6 +60,7 @@ type Advertise = { export default function DetailContent() { const params = useParams(); const id = params?.id; + const slug = params?.slug; const pathname = usePathname(); const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); @@ -252,8 +259,8 @@ export default function DetailContent() { async function initStateData() { loading(); - const res = await getArticleById(id); - const data = res.data?.data; + const res = await getArticleBySlug(slug); + const data = res?.data?.data; setThumbnail(data?.thumbnailUrl); setDiseId(data?.aiArticleId); @@ -524,9 +531,17 @@ export default function DetailContent() {
{articleDetail?.tags ? ( - - {articleDetail.tags} - + articleDetail.tags + .split(",") // pisahkan berdasarkan koma + .map((tag: string, index: number) => ( + + {tag.trim()} + + )) ) : ( Tidak ada tag )} @@ -696,7 +711,7 @@ export default function DetailContent() {
{/* Featured Article */}
- + {featured?.title} {others.map((item) => (
- +
{/* Featured Article */}
- + {featured?.title} {others.map((item) => (
- +
- + {featured?.title} {others.map((item) => (
- +
- + {featured?.title} {others.map((item) => (
- +
- +

{item.title}

diff --git a/components/landing-page/opini.tsx b/components/landing-page/opini.tsx index 0bd628f..1da7205 100644 --- a/components/landing-page/opini.tsx +++ b/components/landing-page/opini.tsx @@ -15,6 +15,7 @@ type Article = { id: number; title: string; createdAt: string; + slug: string; thumbnailUrl?: string; categories: Category[]; }; @@ -52,7 +53,7 @@ function NewsColumn({ title, color, items }: NewsColumnProps) { className={`flex flex-col ${ index === 0 ? "md:flex-row" : "" } border-b border-gray-200 pb-3`} - href={`/detail/${item?.id}`} + href={`/details/${item?.slug}`} > {index === 0 && item?.thumbnailUrl && (
diff --git a/components/landing-page/service.tsx b/components/landing-page/service.tsx index db428ac..1496656 100644 --- a/components/landing-page/service.tsx +++ b/components/landing-page/service.tsx @@ -11,6 +11,7 @@ type Article = { description: string; categoryName: string; createdAt: string; + slug: string; createdByName: string; thumbnailUrl: string; categories: { @@ -51,7 +52,7 @@ export default function HeadersService() { return (
- + {featured?.title} {others.map((item) => (
- +
{ + const copyUrlArticle = async (slug: any) => { const url = `${window.location.protocol}//${window.location.host}` + - "/detail/" + - `${id}`; + "/details/" + + `${slug}`; try { await navigator.clipboard.writeText(url); successToast("Success", "Article Copy to Clipboard"); @@ -263,7 +263,9 @@ export default function ArticleTable() { - copyUrlArticle(article.id)}> + copyUrlArticle(article.slug)} + > Copy Url Article diff --git a/service/article.ts b/service/article.ts index 569cef0..4f338cd 100644 --- a/service/article.ts +++ b/service/article.ts @@ -106,6 +106,13 @@ export async function getArticleById(id: any) { return await httpGet(`/articles/${id}`, headers); } +export async function getArticleBySlug(slug: any) { + const headers = { + "content-type": "application/json", + }; + return await httpGet(`/articles/slug/${slug}`, headers); +} + export async function deleteArticle(id: string) { const headers = { "content-type": "application/json",