update
This commit is contained in:
parent
bb1a83f387
commit
4dcc9285d1
|
|
@ -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 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 { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
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";
|
||||||
|
|
||||||
|
|
@ -54,6 +59,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 [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const [totalPage, setTotalPage] = useState(1);
|
const [totalPage, setTotalPage] = useState(1);
|
||||||
|
|
@ -295,13 +301,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -537,9 +543,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>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ type Article = {
|
||||||
categoryName: string;
|
categoryName: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
createdByName: string;
|
createdByName: string;
|
||||||
|
slug: string;
|
||||||
customCreatorName: string;
|
customCreatorName: string;
|
||||||
thumbnailUrl: string;
|
thumbnailUrl: string;
|
||||||
categories: {
|
categories: {
|
||||||
|
|
@ -112,7 +113,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}
|
||||||
|
|
@ -192,7 +193,7 @@ export default function BreakingNews() {
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Link
|
<Link
|
||||||
className="flex flex-col gap-4"
|
className="flex flex-col gap-4"
|
||||||
href={`/detail/${popular[0]?.id}`}
|
href={`/details/${popular[0]?.slug}`}
|
||||||
>
|
>
|
||||||
<Image
|
<Image
|
||||||
src={popular[0]?.files?.[0]?.fileUrl || "/dummy.jpg"}
|
src={popular[0]?.files?.[0]?.fileUrl || "/dummy.jpg"}
|
||||||
|
|
@ -223,7 +224,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>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ type Article = {
|
||||||
description: string;
|
description: string;
|
||||||
categoryName: string;
|
categoryName: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
|
slug: string;
|
||||||
createdByName: string;
|
createdByName: string;
|
||||||
customCreatorName: string;
|
customCreatorName: string;
|
||||||
thumbnailUrl: string;
|
thumbnailUrl: string;
|
||||||
|
|
@ -52,7 +53,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" href={`/detail/${article?.id}`}>
|
<Link className="flex" href={`/details/${article?.slug}`}>
|
||||||
{/* Gambar utama */}
|
{/* Gambar utama */}
|
||||||
<Image
|
<Image
|
||||||
src={article?.thumbnailUrl || "/dummy.jpg"}
|
src={article?.thumbnailUrl || "/dummy.jpg"}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ type Article = {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
|
slug: string;
|
||||||
createdByName: string;
|
createdByName: string;
|
||||||
customCreatorName: string;
|
customCreatorName: string;
|
||||||
thumbnailUrl: string;
|
thumbnailUrl: string;
|
||||||
|
|
@ -90,7 +91,7 @@ export default function HeaderNews() {
|
||||||
<div className="py-6 grid grid-cols-1 md:grid-cols-2 gap-4 h-[600px]">
|
<div className="py-6 grid grid-cols-1 md:grid-cols-2 gap-4 h-[600px]">
|
||||||
{/* Kiri - berita utama */}
|
{/* Kiri - berita utama */}
|
||||||
<div className="relative overflow-hidden h-full">
|
<div className="relative overflow-hidden h-full">
|
||||||
<Link className="flex" href={`/detail/${articles[0]?.id}`}>
|
<Link className="flex" href={`/details/${articles[0]?.slug}`}>
|
||||||
<Image
|
<Image
|
||||||
src={articles[0]?.thumbnailUrl || "/dummy.jpg"}
|
src={articles[0]?.thumbnailUrl || "/dummy.jpg"}
|
||||||
alt={articles[0]?.title || "No Title"}
|
alt={articles[0]?.title || "No Title"}
|
||||||
|
|
@ -130,7 +131,7 @@ export default function HeaderNews() {
|
||||||
key={item.id || `dummy-${idx}`}
|
key={item.id || `dummy-${idx}`}
|
||||||
className="relative overflow-hidden"
|
className="relative overflow-hidden"
|
||||||
>
|
>
|
||||||
<Link className="flex" href={`/detail/${item?.id}`}>
|
<Link className="flex" href={`/details/${item?.slug}`}>
|
||||||
<Image
|
<Image
|
||||||
src={item.thumbnailUrl || "/dummy.jpg"}
|
src={item.thumbnailUrl || "/dummy.jpg"}
|
||||||
alt={item.title || "No Title"}
|
alt={item.title || "No Title"}
|
||||||
|
|
@ -170,7 +171,7 @@ export default function HeaderNews() {
|
||||||
{/* Bawah: 1 berita besar */}
|
{/* Bawah: 1 berita besar */}
|
||||||
{articles[3] && (
|
{articles[3] && (
|
||||||
<div className="relative overflow-hidden">
|
<div className="relative overflow-hidden">
|
||||||
<Link className="flex" href={`/detail/${articles[3]?.id}`}>
|
<Link className="flex" href={`/details/${articles[3]?.slug}`}>
|
||||||
<Image
|
<Image
|
||||||
src={articles[3]?.thumbnailUrl || "/dummy.jpg"}
|
src={articles[3]?.thumbnailUrl || "/dummy.jpg"}
|
||||||
alt={articles[3]?.title || "No Title"}
|
alt={articles[3]?.title || "No Title"}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ type Article = {
|
||||||
title: string;
|
title: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
createdByName: string;
|
createdByName: string;
|
||||||
|
slug: string;
|
||||||
customCreatorName: string;
|
customCreatorName: string;
|
||||||
thumbnailUrl: string;
|
thumbnailUrl: string;
|
||||||
categories: { title: string }[];
|
categories: { title: string }[];
|
||||||
|
|
@ -93,7 +94,7 @@ export default function Story() {
|
||||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||||
{articles.map((item) => (
|
{articles.map((item) => (
|
||||||
<div key={item.id} className="relative overflow-hidden h-72">
|
<div key={item.id} className="relative overflow-hidden h-72">
|
||||||
<Link className="flex" href={`/detail/${item?.id}`}>
|
<Link className="flex" href={`/details/${item?.slug}`}>
|
||||||
<Image
|
<Image
|
||||||
src={item.thumbnailUrl || "/dummy.jpg"}
|
src={item.thumbnailUrl || "/dummy.jpg"}
|
||||||
alt={item.title}
|
alt={item.title}
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue