This commit is contained in:
Anang Yusman 2025-11-02 18:15:54 +08:00
parent 325d31cd38
commit 41c818fe47
10 changed files with 70 additions and 21 deletions

View File

@ -0,0 +1,19 @@
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 (
<div className="relative min-h-screen font-[family-name:var(--font-geist-sans)]">
<div className="relative z-10 bg-[#F2F4F3] max-w-7xl mx-auto">
<Navbar />
<div className="flex-1">
<DetailContent />
</div>
<Footer />
</div>
</div>
);
}

View File

@ -2,7 +2,11 @@
import Image from "next/image"; import Image from "next/image";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import Link from "next/link"; 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 { close, error, loading } from "@/config/swal";
import { useParams, usePathname } from "next/navigation"; import { useParams, usePathname } from "next/navigation";
import Author from "../landing-page/author"; import Author from "../landing-page/author";
@ -16,6 +20,7 @@ import {
} from "@/service/master-user"; } from "@/service/master-user";
import { saveActivity } from "@/service/activity-log"; import { saveActivity } from "@/service/activity-log";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { Badge } from "../ui/badge";
type TabKey = "trending" | "comments" | "latest"; type TabKey = "trending" | "comments" | "latest";
@ -25,6 +30,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { categories: {
@ -54,6 +60,7 @@ type Advertise = {
export default function DetailContent() { export default function DetailContent() {
const params = useParams(); const params = useParams();
const id = params?.id; const id = params?.id;
const slug = params?.slug;
const pathname = usePathname(); const pathname = usePathname();
const [page, setPage] = useState(1); const [page, setPage] = useState(1);
const [totalPage, setTotalPage] = useState(1); const [totalPage, setTotalPage] = useState(1);
@ -295,13 +302,13 @@ export default function DetailContent() {
async function initStateData() { async function initStateData() {
loading(); loading();
const res = await getArticleById(id); const res = await getArticleBySlug(slug);
const data = res.data?.data; const data = res?.data?.data;
setThumbnail(data?.thumbnailUrl); setThumbnail(data?.thumbnailUrl);
setDiseId(data?.aiArticleId); setDiseId(data?.aiArticleId);
setDetailFiles(data?.files); setDetailFiles(data?.files);
setArticleDetail(data); setArticleDetail(data); // <-- Add this
close(); close();
} }
@ -543,9 +550,17 @@ export default function DetailContent() {
</span> </span>
<div className="flex flex-wrap gap-2 mt-1"> <div className="flex flex-wrap gap-2 mt-1">
{articleDetail?.tags ? ( {articleDetail?.tags ? (
<span className="bg-gray-100 text-gray-700 text-sm px-2 py-1 rounded"> articleDetail.tags
{articleDetail.tags} .split(",") // pisahkan berdasarkan koma
</span> .map((tag: string, index: number) => (
<Badge
key={index}
variant="secondary"
className="text-sm"
>
{tag.trim()}
</Badge>
))
) : ( ) : (
<span className="text-sm text-gray-500">Tidak ada tag</span> <span className="text-sm text-gray-500">Tidak ada tag</span>
)} )}

View File

@ -13,6 +13,7 @@ type Article = {
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
createdByName: string; createdByName: string;
slug: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { categories: {
title: string; title: string;
@ -111,7 +112,7 @@ export default function BreakingNews() {
<div className="md:col-span-2 space-y-6"> <div className="md:col-span-2 space-y-6">
{articles.map((item) => ( {articles.map((item) => (
<div key={item.id} className="flex gap-4 border-b pb-4"> <div key={item.id} className="flex gap-4 border-b pb-4">
<Link className="flex gap-4" href={`/detail/${item?.id}`}> <Link className="flex gap-4" href={`/details/${item?.slug}`}>
<Image <Image
src={item.thumbnailUrl || "/dummy.jpg"} src={item.thumbnailUrl || "/dummy.jpg"}
alt={item.title} alt={item.title}
@ -187,7 +188,7 @@ export default function BreakingNews() {
{popular.length > 0 && ( {popular.length > 0 && (
<div className="space-y-5"> <div className="space-y-5">
<Link className="flex gap-4" href={`/detail/${popular[0]?.id}`}> <Link className="flex gap-4" href={`/details/${popular[0]?.slug}`}>
{/* Item pertama tampil besar */} {/* Item pertama tampil besar */}
<div className="relative"> <div className="relative">
<Image <Image
@ -218,7 +219,7 @@ export default function BreakingNews() {
key={item.id} key={item.id}
className="flex gap-3 items-start border-b pb-2 last:border-b-0" className="flex gap-3 items-start border-b pb-2 last:border-b-0"
> >
<Link className="flex gap-4" href={`/detail/${item?.id}`}> <Link className="flex gap-4" href={`/details/${item?.slug}`}>
<span className="text-lg font-bold text-gray-400"> <span className="text-lg font-bold text-gray-400">
0{i + 2} 0{i + 2}
</span> </span>

View File

@ -11,6 +11,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { categories: {
@ -51,7 +52,7 @@ export default function HeaderLatest() {
return ( return (
<header className="w-full pt-3 flex justify-center"> <header className="w-full pt-3 flex justify-center">
<div className="relative max-w-screen-xl w-full h-[320px] md:h-[480px] mx-3 md:mx-5 overflow-hidden group"> <div className="relative max-w-screen-xl w-full h-[320px] md:h-[480px] mx-3 md:mx-5 overflow-hidden group">
<Link className="flex gap-4" href={`/detail/${article?.id}`}> <Link className="flex gap-4" href={`/details/${article?.slug}`}>
<Image <Image
src={article?.thumbnailUrl || "/dummy.jpg"} src={article?.thumbnailUrl || "/dummy.jpg"}
alt={article?.title || "No Title"} alt={article?.title || "No Title"}

View File

@ -11,6 +11,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { categories: {
@ -52,7 +53,7 @@ export default function Header() {
return ( return (
<header className="bg-white w-full pt-3 flex justify-center"> <header className="bg-white w-full pt-3 flex justify-center">
<div className="relative max-w-screen-xl h-auto md:h-[483px] flex flex-col md:flex-row overflow-hidden shadow-md mx-3 md:mx-3 lg:mx-5"> <div className="relative max-w-screen-xl h-auto md:h-[483px] flex flex-col md:flex-row overflow-hidden shadow-md mx-3 md:mx-3 lg:mx-5">
<Link className="flex" href={`/detail/${article?.id}`}> <Link className="flex" href={`/details/${article?.slug}`}>
<div className="w-full md:w-1/2 h-[250px] md:h-full"> <div className="w-full md:w-1/2 h-[250px] md:h-full">
<Image <Image
src={article?.thumbnailUrl || "/dummy.jpg"} src={article?.thumbnailUrl || "/dummy.jpg"}

View File

@ -23,6 +23,7 @@ type Article = {
createdAt: string; createdAt: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
slug: string;
categories: { categories: {
title: string; title: string;
}[]; }[];
@ -129,7 +130,7 @@ export default function News() {
key={item.id} key={item.id}
className="flex flex-col md:flex-row gap-4 pb-6" className="flex flex-col md:flex-row gap-4 pb-6"
> >
<Link className="flex gap-4" href={`/detail/${item?.id}`}> <Link className="flex gap-4" href={`/details/${item?.slug}`}>
<div className="w-full md:w-[250px]"> <div className="w-full md:w-[250px]">
<Image <Image
src={item.thumbnailUrl || "/dummy.jpg"} src={item.thumbnailUrl || "/dummy.jpg"}

View File

@ -12,6 +12,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { categories: {
@ -122,7 +123,7 @@ export default function Opini() {
key={item.id} key={item.id}
className="flex items-start gap-4 border-b pb-4" className="flex items-start gap-4 border-b pb-4"
> >
<Link className="flex gap-4" href={`/detail/${item?.id}`}> <Link className="flex gap-4" href={`/details/${item?.slug}`}>
<Image <Image
src={item.thumbnailUrl || "/dummy.jpg"} src={item.thumbnailUrl || "/dummy.jpg"}
alt={item.title} alt={item.title}
@ -187,7 +188,7 @@ export default function Opini() {
{jagaNegeri.length > 0 && ( {jagaNegeri.length > 0 && (
<div className="mt-6 flex flex-col md:flex-row gap-6"> <div className="mt-6 flex flex-col md:flex-row gap-6">
<Link className="flex" href={`/detail/${jagaNegeri[0]?.id}`}> <Link className="flex" href={`/details/${jagaNegeri[0]?.slug}`}>
<div className="w-full md:w-[455px]"> <div className="w-full md:w-[455px]">
<Image <Image
src={jagaNegeri[0].thumbnailUrl || "/dummy.jpg"} src={jagaNegeri[0].thumbnailUrl || "/dummy.jpg"}
@ -215,7 +216,7 @@ export default function Opini() {
<div className="w-full md:w-4/12 flex flex-col gap-4"> <div className="w-full md:w-4/12 flex flex-col gap-4">
{jagaNegeri.slice(1).map((item) => ( {jagaNegeri.slice(1).map((item) => (
<div key={item.id} className="flex flex-col gap-3"> <div key={item.id} className="flex flex-col gap-3">
<Link className=" gap-3" href={`/detail/${item?.id}`}> <Link className=" gap-3" href={`/details/${item?.slug}`}>
<Image <Image
src={item.thumbnailUrl || "/dummy.jpg"} src={item.thumbnailUrl || "/dummy.jpg"}
alt={item.title} alt={item.title}

View File

@ -13,6 +13,7 @@ type Article = {
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
createdByName: string; createdByName: string;
slug: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { categories: {
title: string; title: string;
@ -104,7 +105,7 @@ export default function PopularNews() {
key={news.id} key={news.id}
className="relative h-[358px] group overflow-hidden" className="relative h-[358px] group overflow-hidden"
> >
<Link className=" gap-3" href={`/detail/${news?.id}`}> <Link className=" gap-3" href={`/details/${news?.slug}`}>
<Image <Image
src={news.thumbnailUrl || "/dummy.jpg"} src={news.thumbnailUrl || "/dummy.jpg"}
alt={news.title} alt={news.title}

View File

@ -199,11 +199,11 @@ export default function ArticleTable() {
initState(); initState();
}; };
const copyUrlArticle = async (id: number) => { const copyUrlArticle = async (slug: any) => {
const url = const url =
`${window.location.protocol}//${window.location.host}` + `${window.location.protocol}//${window.location.host}` +
"/detail/" + "/details/" +
`${id}`; `${slug}`;
try { try {
await navigator.clipboard.writeText(url); await navigator.clipboard.writeText(url);
successToast("Success", "Article Copy to Clipboard"); successToast("Success", "Article Copy to Clipboard");
@ -263,7 +263,9 @@ export default function ArticleTable() {
</Button> </Button>
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent className="w-56"> <DropdownMenuContent className="w-56">
<DropdownMenuItem onClick={() => copyUrlArticle(article.id)}> <DropdownMenuItem
onClick={() => copyUrlArticle(article.slug)}
>
<CopyIcon className="mr-2 h-4 w-4" /> <CopyIcon className="mr-2 h-4 w-4" />
Copy Url Article Copy Url Article
</DropdownMenuItem> </DropdownMenuItem>

View File

@ -106,6 +106,13 @@ export async function getArticleById(id: any) {
return await httpGet(`/articles/${id}`, headers); 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) { export async function deleteArticle(id: string) {
const headers = { const headers = {
"content-type": "application/json", "content-type": "application/json",