This commit is contained in:
Anang Yusman 2025-11-02 17:55:22 +08:00
parent 8fce67a4dd
commit cb9b285ca7
9 changed files with 69 additions and 23 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 {
postArticleComment, postArticleComment,
} from "@/service/master-user"; } from "@/service/master-user";
import { saveActivity } from "@/service/activity-log"; import { saveActivity } from "@/service/activity-log";
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,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();
} }
@ -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

@ -11,6 +11,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;
@ -49,7 +50,7 @@ export default function BottomArticlesSection() {
<div className="max-w-[1300px] mx-auto grid grid-cols-1 md:grid-cols-3 gap-8"> <div className="max-w-[1300px] mx-auto grid grid-cols-1 md:grid-cols-3 gap-8">
{articles.map((item) => ( {articles.map((item) => (
<div key={item.id}> <div key={item.id}>
<Link className="flex gap-4" href={`/detail/${item?.id}`}> <Link className="flex gap-4" href={`/details/${item?.slug}`}>
<div className="relative w-[120px] h-[100px] shrink-0"> <div className="relative w-[120px] h-[100px] shrink-0">
<Image <Image
src={ src={

View File

@ -10,6 +10,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 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}
@ -149,7 +150,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
@ -180,7 +181,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 = {
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;
@ -60,7 +61,7 @@ export default function Header() {
key={item.id} key={item.id}
className="relative w-full h-[220px] md:h-[400px] overflow-hidden" className="relative w-full h-[220px] md:h-[400px] overflow-hidden"
> >
<Link href={`/detail/${item?.id}`}> <Link href={`/details/${item?.slug}`}>
<Image <Image
src={item.thumbnailUrl || "/default.jpg"} src={item.thumbnailUrl || "/default.jpg"}
alt={item.title} alt={item.title}
@ -102,7 +103,7 @@ export default function Header() {
key={item.id} key={item.id}
className="flex flex-col md:flex-row gap-4 overflow-hidden" className="flex flex-col md:flex-row gap-4 overflow-hidden"
> >
<Link href={`/detail/${item?.id}`}> <Link href={`/details/${item?.slug}`}>
<div className="relative w-full md:w-[200px] h-[180px] md:h-[175px] shrink-0"> <div className="relative w-full md:w-[200px] h-[180px] md:h-[175px] shrink-0">
<Image <Image
src={item.thumbnailUrl || "/default.jpg"} src={item.thumbnailUrl || "/default.jpg"}

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;
@ -87,7 +88,7 @@ export default function HeaderLatest() {
<div className="grid grid-cols-1 md:grid-cols-2 gap-6"> <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
{articles.map((article) => ( {articles.map((article) => (
<div key={article.id}> <div key={article.id}>
<Link href={`/detail/${article.id}`}> <Link href={`/details/${article.slug}`}>
<Image <Image
src={article.thumbnailUrl || "/default.jpg"} src={article.thumbnailUrl || "/default.jpg"}
alt={article.title} alt={article.title}
@ -113,7 +114,7 @@ export default function HeaderLatest() {
})} })}
</p> </p>
<Link <Link
href={`/detail/${article.id}`} href={`/details/${article.slug}`}
className="mt-2 inline-block text-sm text-yellow-600 font-semibold hover:underline" className="mt-2 inline-block text-sm text-yellow-600 font-semibold hover:underline"
> >
READ MORE &gt; READ MORE &gt;
@ -144,7 +145,7 @@ export default function HeaderLatest() {
<h4 className="text-xl font-bold">Recent Posts</h4> <h4 className="text-xl font-bold">Recent Posts</h4>
{recentPosts.map((post, index) => ( {recentPosts.map((post, index) => (
<div key={post.id}> <div key={post.id}>
<Link className="flex gap-3" href={`/detail/${post.id}`}> <Link className="flex gap-3" href={`/details/${post.slug}`}>
<Image <Image
src={post.thumbnailUrl || "/default.jpg"} src={post.thumbnailUrl || "/default.jpg"}
alt={post.title} alt={post.title}

View File

@ -112,7 +112,7 @@ export default function News() {
<div className="grid grid-cols-1 md:grid-cols-2 gap-8"> <div className="grid grid-cols-1 md:grid-cols-2 gap-8">
{articles.slice(0, 4).map((article) => ( {articles.slice(0, 4).map((article) => (
<div key={article.id}> <div key={article.id}>
<Link href={`/detail/${article?.id}`}> <Link href={`/details/${article?.slug}`}>
<div className="w-full h-[280px] relative overflow-hidden"> <div className="w-full h-[280px] relative overflow-hidden">
<Image <Image
src={ src={
@ -184,7 +184,7 @@ export default function News() {
<div className="grid grid-cols-1 md:grid-cols-2 gap-8"> <div className="grid grid-cols-1 md:grid-cols-2 gap-8">
{articles.slice(4, 8).map((article) => ( {articles.slice(4, 8).map((article) => (
<div key={article.id}> <div key={article.id}>
<Link href={`/detail/${article?.id}`}> <Link href={`/details/${article?.slug}`}>
<div className="w-full h-[280px] relative overflow-hidden"> <div className="w-full h-[280px] relative overflow-hidden">
<Image <Image
src={ src={
@ -295,7 +295,7 @@ export default function News() {
<div key={item.id}> <div key={item.id}>
<Link <Link
className="flex items-start gap-3" className="flex items-start gap-3"
href={`/detail/${item?.id}`} href={`/details/${item?.slug}`}
> >
<div className="w-[80px] h-[80px] relative shrink-0"> <div className="w-[80px] h-[80px] relative shrink-0">
<Image <Image

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