update
This commit is contained in:
parent
c912b21b66
commit
1787bc51f6
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
@ -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 { Link2, MailIcon } from "lucide-react";
|
||||
|
|
@ -16,6 +20,7 @@ import {
|
|||
} from "@/service/master-user";
|
||||
import { saveActivity } from "@/service/activity-log";
|
||||
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);
|
||||
|
|
@ -296,13 +303,13 @@ 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);
|
||||
setDetailFiles(data?.files);
|
||||
setArticleDetail(data);
|
||||
setArticleDetail(data); // <-- Add this
|
||||
close();
|
||||
}
|
||||
|
||||
|
|
@ -526,9 +533,17 @@ export default function DetailContent() {
|
|||
</span>
|
||||
<div className="flex flex-wrap gap-2 mt-1">
|
||||
{articleDetail?.tags ? (
|
||||
<span className="bg-gray-100 text-gray-700 text-sm px-2 py-1 rounded">
|
||||
{articleDetail.tags}
|
||||
</span>
|
||||
articleDetail.tags
|
||||
.split(",") // pisahkan berdasarkan koma
|
||||
.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>
|
||||
)}
|
||||
|
|
@ -724,7 +739,7 @@ export default function DetailContent() {
|
|||
{/* Artikel utama (featured) */}
|
||||
{articles.length > 0 && (
|
||||
<div className="relative">
|
||||
<Link href={`/detail/${articles[0]?.id}`}>
|
||||
<Link href={`/details/${articles[0]?.slug}`}>
|
||||
<Image
|
||||
src={articles[0]?.thumbnailUrl || "/default.jpg"}
|
||||
alt={articles[0]?.title || "Recommended Article"}
|
||||
|
|
@ -758,7 +773,7 @@ export default function DetailContent() {
|
|||
<div key={item.id}>
|
||||
<Link
|
||||
className="flex space-x-3"
|
||||
href={`/detail/${item?.id}`}
|
||||
href={`/details/${item?.slug}`}
|
||||
>
|
||||
<Image
|
||||
src={item.thumbnailUrl || "/default.jpg"}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ type Article = {
|
|||
description: string;
|
||||
categoryName: string;
|
||||
createdAt: string;
|
||||
slug: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
categories: { title: string }[];
|
||||
|
|
@ -51,7 +52,7 @@ export default function BannerNews() {
|
|||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4 p-4">
|
||||
{/* Artikel utama */}
|
||||
<div className="lg:col-span-2 relative">
|
||||
<Link href={`/detail/${mainArticle?.id}`}>
|
||||
<Link href={`/details/${mainArticle?.slug}`}>
|
||||
<img
|
||||
src={mainArticle.thumbnailUrl || mainArticle.files?.[0]?.fileUrl}
|
||||
alt={mainArticle.files?.[0]?.file_alt || mainArticle.title}
|
||||
|
|
@ -72,7 +73,7 @@ export default function BannerNews() {
|
|||
<div className="grid grid-cols-1 gap-4">
|
||||
{sideArticles.map((article) => (
|
||||
<div key={article.id} className="relative">
|
||||
<Link href={`/detail/${article?.id}`}>
|
||||
<Link href={`/details/${article?.slug}`}>
|
||||
<img
|
||||
src={article.thumbnailUrl || article.files?.[0]?.fileUrl}
|
||||
alt={article.files?.[0]?.file_alt || article.title}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ type Article = {
|
|||
description: string;
|
||||
categoryName: string;
|
||||
createdAt: string;
|
||||
slug: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
categories: { title: string }[];
|
||||
|
|
@ -79,7 +80,7 @@ export default function BreakingNews() {
|
|||
key={article.id}
|
||||
className="bg-white border overflow-hidden shadow-sm hover:shadow-md transition"
|
||||
>
|
||||
<Link href={`/detail/${article?.id}`}>
|
||||
<Link href={`/details/${article?.slug}`}>
|
||||
<div className="relative w-full h-40">
|
||||
<Image
|
||||
src={
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -98,7 +99,7 @@ export default function Header() {
|
|||
key={post.id}
|
||||
className="relative group overflow-hidden h-56 md:h-64"
|
||||
>
|
||||
<Link href={`/detail/${post?.id}`}>
|
||||
<Link href={`/details/${post?.slug}`}>
|
||||
<Image
|
||||
src={post.thumbnailUrl || "/default.jpg"}
|
||||
alt={post.title}
|
||||
|
|
@ -144,7 +145,7 @@ export default function Header() {
|
|||
key={post.id}
|
||||
className="relative group overflow-hidden h-56 md:h-64"
|
||||
>
|
||||
<Link href={`/detail/${post?.id}`}>
|
||||
<Link href={`/details/${post?.slug}`}>
|
||||
<Image
|
||||
src={post.thumbnailUrl || "/default.jpg"}
|
||||
alt={post.title}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ type Article = {
|
|||
description: string;
|
||||
categoryName: string;
|
||||
createdAt: string;
|
||||
slug: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
categories: { title: string }[];
|
||||
|
|
@ -102,7 +103,7 @@ export default function LatestNews() {
|
|||
{articles.slice(0, 5).map((article, index) => (
|
||||
<Link
|
||||
key={article.id}
|
||||
href={`/detail/${article.id}`}
|
||||
href={`/details/${article.slug}`}
|
||||
className={`grid grid-cols-1 md:grid-cols-2 gap-4 mb-6 items-center`}
|
||||
>
|
||||
{/* Gambar */}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ type Article = {
|
|||
description: string;
|
||||
categoryName: string;
|
||||
createdAt: string;
|
||||
slug: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
categories: { title: string }[];
|
||||
|
|
@ -221,7 +222,10 @@ export default function News() {
|
|||
function PostItem({ post }: { post: Article }) {
|
||||
return (
|
||||
<div className="flex gap-4 mb-6 pb-4">
|
||||
<Link className="flex items-center gap-4 " href={`/detail/${post?.id}`}>
|
||||
<Link
|
||||
className="flex items-center gap-4 "
|
||||
href={`/details/${post?.slug}`}
|
||||
>
|
||||
<div className="relative w-40 h-28 flex-shrink-0">
|
||||
<Image
|
||||
src={
|
||||
|
|
|
|||
|
|
@ -199,11 +199,11 @@ export default function ArticleTable() {
|
|||
initState();
|
||||
};
|
||||
|
||||
const copyUrlArticle = async (id: number) => {
|
||||
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() {
|
|||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-56">
|
||||
<DropdownMenuItem onClick={() => copyUrlArticle(article.id)}>
|
||||
<DropdownMenuItem
|
||||
onClick={() => copyUrlArticle(article.slug)}
|
||||
>
|
||||
<CopyIcon className="mr-2 h-4 w-4" />
|
||||
Copy Url Article
|
||||
</DropdownMenuItem>
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue