update
This commit is contained in:
parent
8fce67a4dd
commit
cb9b285ca7
|
|
@ -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 Author from "../landing-page/author";
|
||||
|
|
@ -16,6 +20,7 @@ import {
|
|||
postArticleComment,
|
||||
} from "@/service/master-user";
|
||||
import { saveActivity } from "@/service/activity-log";
|
||||
import { Badge } from "../ui/badge";
|
||||
|
||||
type TabKey = "trending" | "comments" | "latest";
|
||||
|
||||
|
|
@ -55,6 +60,7 @@ interface CategoryType {
|
|||
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 +302,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 +532,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>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: 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">
|
||||
{articles.map((item) => (
|
||||
<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">
|
||||
<Image
|
||||
src={
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -73,7 +74,7 @@ export default function BreakingNews() {
|
|||
<div className="md:col-span-2 space-y-6">
|
||||
{articles.map((item) => (
|
||||
<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
|
||||
src={item.thumbnailUrl || "/dummy.jpg"}
|
||||
alt={item.title}
|
||||
|
|
@ -149,7 +150,7 @@ export default function BreakingNews() {
|
|||
|
||||
{popular.length > 0 && (
|
||||
<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 */}
|
||||
<div className="relative">
|
||||
<Image
|
||||
|
|
@ -180,7 +181,7 @@ export default function BreakingNews() {
|
|||
key={item.id}
|
||||
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">
|
||||
0{i + 2}
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -60,7 +61,7 @@ export default function Header() {
|
|||
key={item.id}
|
||||
className="relative w-full h-[220px] md:h-[400px] overflow-hidden"
|
||||
>
|
||||
<Link href={`/detail/${item?.id}`}>
|
||||
<Link href={`/details/${item?.slug}`}>
|
||||
<Image
|
||||
src={item.thumbnailUrl || "/default.jpg"}
|
||||
alt={item.title}
|
||||
|
|
@ -102,7 +103,7 @@ export default function Header() {
|
|||
key={item.id}
|
||||
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">
|
||||
<Image
|
||||
src={item.thumbnailUrl || "/default.jpg"}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -87,7 +88,7 @@ export default function HeaderLatest() {
|
|||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
{articles.map((article) => (
|
||||
<div key={article.id}>
|
||||
<Link href={`/detail/${article.id}`}>
|
||||
<Link href={`/details/${article.slug}`}>
|
||||
<Image
|
||||
src={article.thumbnailUrl || "/default.jpg"}
|
||||
alt={article.title}
|
||||
|
|
@ -113,7 +114,7 @@ export default function HeaderLatest() {
|
|||
})}
|
||||
</p>
|
||||
<Link
|
||||
href={`/detail/${article.id}`}
|
||||
href={`/details/${article.slug}`}
|
||||
className="mt-2 inline-block text-sm text-yellow-600 font-semibold hover:underline"
|
||||
>
|
||||
READ MORE >
|
||||
|
|
@ -144,7 +145,7 @@ export default function HeaderLatest() {
|
|||
<h4 className="text-xl font-bold">Recent Posts</h4>
|
||||
{recentPosts.map((post, index) => (
|
||||
<div key={post.id}>
|
||||
<Link className="flex gap-3" href={`/detail/${post.id}`}>
|
||||
<Link className="flex gap-3" href={`/details/${post.slug}`}>
|
||||
<Image
|
||||
src={post.thumbnailUrl || "/default.jpg"}
|
||||
alt={post.title}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ export default function News() {
|
|||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
{articles.slice(0, 4).map((article) => (
|
||||
<div key={article.id}>
|
||||
<Link href={`/detail/${article?.id}`}>
|
||||
<Link href={`/details/${article?.slug}`}>
|
||||
<div className="w-full h-[280px] relative overflow-hidden">
|
||||
<Image
|
||||
src={
|
||||
|
|
@ -184,7 +184,7 @@ export default function News() {
|
|||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
{articles.slice(4, 8).map((article) => (
|
||||
<div key={article.id}>
|
||||
<Link href={`/detail/${article?.id}`}>
|
||||
<Link href={`/details/${article?.slug}`}>
|
||||
<div className="w-full h-[280px] relative overflow-hidden">
|
||||
<Image
|
||||
src={
|
||||
|
|
@ -295,7 +295,7 @@ export default function News() {
|
|||
<div key={item.id}>
|
||||
<Link
|
||||
className="flex items-start gap-3"
|
||||
href={`/detail/${item?.id}`}
|
||||
href={`/details/${item?.slug}`}
|
||||
>
|
||||
<div className="w-[80px] h-[80px] relative shrink-0">
|
||||
<Image
|
||||
|
|
|
|||
|
|
@ -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