This commit is contained in:
Anang Yusman 2025-11-02 14:32:10 +08:00
parent 1e66c47338
commit f483a81b42
7 changed files with 64 additions and 19 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";
@ -17,6 +21,7 @@ import {
postArticleComment, postArticleComment,
} from "@/service/master-user"; } from "@/service/master-user";
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";
@ -55,6 +60,7 @@ interface CategoryType {
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);
@ -296,7 +302,7 @@ 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);
@ -526,9 +532,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 = {
title: string; title: string;
description: string; description: string;
categoryName: string; categoryName: string;
slug: string;
createdAt: string; createdAt: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
@ -123,7 +124,7 @@ export default function BreakingNews() {
<div className="w-9/12"> <div className="w-9/12">
{mainArticle && ( {mainArticle && (
<div className=""> <div className="">
<Link href={`/detail/${mainArticle?.id}`}> <Link href={`/details/${mainArticle?.slug}`}>
<div className="grid md:grid-cols-2 gap-6 items-center"> <div className="grid md:grid-cols-2 gap-6 items-center">
{/* LEFT - Image */} {/* LEFT - Image */}
<div className="relative w-full h-[220px] md:h-[300px] overflow-hidden"> <div className="relative w-full h-[220px] md:h-[300px] overflow-hidden">
@ -227,7 +228,7 @@ export default function BreakingNews() {
return ( return (
<div key={article.id} className="group"> <div key={article.id} className="group">
<Link href={`/detail/${article?.id}`}> <Link href={`/details/${article?.slug}`}>
{/* Image */} {/* Image */}
<div className="relative w-full h-[180px] overflow-hidden mb-3"> <div className="relative w-full h-[180px] overflow-hidden mb-3">
<Image <Image
@ -309,7 +310,7 @@ export default function BreakingNews() {
<div key={article.id}> <div key={article.id}>
<Link <Link
className="grid grid-cols-1 md:grid-cols-3 gap-4" className="grid grid-cols-1 md:grid-cols-3 gap-4"
href={`/detail/${article?.id}`} href={`/details/${article?.slug}`}
> >
{/* LEFT - Image */} {/* LEFT - Image */}
<div className="relative w-full h-[180px] md:h-[140px] rounded-md overflow-hidden md:col-span-1"> <div className="relative w-full h-[180px] md:h-[140px] rounded-md overflow-hidden md:col-span-1">
@ -382,7 +383,7 @@ export default function BreakingNews() {
<div key={a.id} className="flex gap-3 items-center"> <div key={a.id} className="flex gap-3 items-center">
<Link <Link
className="flex gap-3 items-center" className="flex gap-3 items-center"
href={`/detail/${a?.id}`} href={`/details/${a?.slug}`}
> >
<div className="relative w-20 h-16 flex-shrink-0 rounded overflow-hidden"> <div className="relative w-20 h-16 flex-shrink-0 rounded overflow-hidden">
<Image <Image
@ -472,7 +473,7 @@ export default function BreakingNews() {
{/* Artikel Utama (Top 1) */} {/* Artikel Utama (Top 1) */}
{popularArticles.length > 0 && ( {popularArticles.length > 0 && (
<div className="mb-6"> <div className="mb-6">
<Link href={`/detail/${popularArticles[0]?.id}`}> <Link href={`/details/${popularArticles[0]?.slug}`}>
<div className="relative w-full h-[220px] md:h-[280px] rounded overflow-hidden"> <div className="relative w-full h-[220px] md:h-[280px] rounded overflow-hidden">
<Image <Image
src={ src={
@ -504,7 +505,7 @@ export default function BreakingNews() {
<div key={a.id}> <div key={a.id}>
<Link <Link
className="flex items-center gap-3" className="flex items-center gap-3"
href={`/detail/${a?.id}`} href={`/details/${a?.slug}`}
> >
{/* Nomor Urut */} {/* Nomor Urut */}
<div className="w-10 h-10 flex items-center justify-center rounded-full border text-sm font-bold text-gray-500"> <div className="w-10 h-10 flex items-center justify-center rounded-full border text-sm font-bold text-gray-500">

View File

@ -12,6 +12,7 @@ type Article = {
title: string; title: string;
description: string; description: string;
categoryName: string; categoryName: string;
slug: string;
createdAt: string; createdAt: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
@ -73,7 +74,7 @@ export default function Header() {
key={article.id} key={article.id}
className="relative h-[438px] md:h-[438px] overflow-hidden" className="relative h-[438px] md:h-[438px] overflow-hidden"
> >
<Link href={`/detail/${article?.id}`}> <Link href={`/details/${article?.slug}`}>
{/* Background Image */} {/* Background Image */}
<Image <Image
src={imageUrl} src={imageUrl}

View File

@ -15,6 +15,7 @@ type Article = {
createdAt: string; createdAt: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
slug: string;
categories: { categories: {
title: string; title: string;
}[]; }[];
@ -140,7 +141,7 @@ export default function BumnNews() {
<div key={item.id}> <div key={item.id}>
<Link <Link
className="flex gap-4 border-b pb-4" className="flex gap-4 border-b pb-4"
href={`/detail/${item?.id}`} href={`/details/${item?.slug}`}
> >
<Image <Image
src={item.thumbnailUrl || "/dummy.jpg"} src={item.thumbnailUrl || "/dummy.jpg"}
@ -205,7 +206,7 @@ export default function BumnNews() {
<div className="space-y-5"> <div className="space-y-5">
{/* Item pertama tampil besar */} {/* Item pertama tampil besar */}
<div className="relative"> <div className="relative">
<Link href={`/detail/${popular[0]?.id}`}> <Link href={`/details/${popular[0]?.slug}`}>
<Image <Image
src={popular[0]?.files?.[0]?.fileUrl || "/dummy.jpg"} src={popular[0]?.files?.[0]?.fileUrl || "/dummy.jpg"}
alt={ alt={
@ -234,7 +235,7 @@ export default function BumnNews() {
<div key={item.id}> <div key={item.id}>
<Link <Link
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"
href={`/detail/${item?.id}`} 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}

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",