update
This commit is contained in:
parent
1e66c47338
commit
f483a81b42
|
|
@ -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";
|
||||
|
|
@ -17,6 +21,7 @@ import {
|
|||
postArticleComment,
|
||||
} from "@/service/master-user";
|
||||
import { useForm } from "react-hook-form";
|
||||
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,7 +302,7 @@ export default function DetailContent() {
|
|||
|
||||
async function initStateData() {
|
||||
loading();
|
||||
const res = await getArticleById(id);
|
||||
const res = await getArticleBySlug(slug);
|
||||
const data = res.data?.data;
|
||||
|
||||
setThumbnail(data?.thumbnailUrl);
|
||||
|
|
@ -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>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -123,7 +124,7 @@ export default function BreakingNews() {
|
|||
<div className="w-9/12">
|
||||
{mainArticle && (
|
||||
<div className="">
|
||||
<Link href={`/detail/${mainArticle?.id}`}>
|
||||
<Link href={`/details/${mainArticle?.slug}`}>
|
||||
<div className="grid md:grid-cols-2 gap-6 items-center">
|
||||
{/* LEFT - Image */}
|
||||
<div className="relative w-full h-[220px] md:h-[300px] overflow-hidden">
|
||||
|
|
@ -227,7 +228,7 @@ export default function BreakingNews() {
|
|||
|
||||
return (
|
||||
<div key={article.id} className="group">
|
||||
<Link href={`/detail/${article?.id}`}>
|
||||
<Link href={`/details/${article?.slug}`}>
|
||||
{/* Image */}
|
||||
<div className="relative w-full h-[180px] overflow-hidden mb-3">
|
||||
<Image
|
||||
|
|
@ -309,7 +310,7 @@ export default function BreakingNews() {
|
|||
<div key={article.id}>
|
||||
<Link
|
||||
className="grid grid-cols-1 md:grid-cols-3 gap-4"
|
||||
href={`/detail/${article?.id}`}
|
||||
href={`/details/${article?.slug}`}
|
||||
>
|
||||
{/* LEFT - Image */}
|
||||
<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">
|
||||
<Link
|
||||
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">
|
||||
<Image
|
||||
|
|
@ -472,7 +473,7 @@ export default function BreakingNews() {
|
|||
{/* Artikel Utama (Top 1) */}
|
||||
{popularArticles.length > 0 && (
|
||||
<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">
|
||||
<Image
|
||||
src={
|
||||
|
|
@ -504,7 +505,7 @@ export default function BreakingNews() {
|
|||
<div key={a.id}>
|
||||
<Link
|
||||
className="flex items-center gap-3"
|
||||
href={`/detail/${a?.id}`}
|
||||
href={`/details/${a?.slug}`}
|
||||
>
|
||||
{/* Nomor Urut */}
|
||||
<div className="w-10 h-10 flex items-center justify-center rounded-full border text-sm font-bold text-gray-500">
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -73,7 +74,7 @@ export default function Header() {
|
|||
key={article.id}
|
||||
className="relative h-[438px] md:h-[438px] overflow-hidden"
|
||||
>
|
||||
<Link href={`/detail/${article?.id}`}>
|
||||
<Link href={`/details/${article?.slug}`}>
|
||||
{/* Background Image */}
|
||||
<Image
|
||||
src={imageUrl}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ type Article = {
|
|||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
slug: string;
|
||||
categories: {
|
||||
title: string;
|
||||
}[];
|
||||
|
|
@ -140,7 +141,7 @@ export default function BumnNews() {
|
|||
<div key={item.id}>
|
||||
<Link
|
||||
className="flex gap-4 border-b pb-4"
|
||||
href={`/detail/${item?.id}`}
|
||||
href={`/details/${item?.slug}`}
|
||||
>
|
||||
<Image
|
||||
src={item.thumbnailUrl || "/dummy.jpg"}
|
||||
|
|
@ -205,7 +206,7 @@ export default function BumnNews() {
|
|||
<div className="space-y-5">
|
||||
{/* Item pertama tampil besar */}
|
||||
<div className="relative">
|
||||
<Link href={`/detail/${popular[0]?.id}`}>
|
||||
<Link href={`/details/${popular[0]?.slug}`}>
|
||||
<Image
|
||||
src={popular[0]?.files?.[0]?.fileUrl || "/dummy.jpg"}
|
||||
alt={
|
||||
|
|
@ -234,7 +235,7 @@ export default function BumnNews() {
|
|||
<div key={item.id}>
|
||||
<Link
|
||||
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">
|
||||
0{i + 2}
|
||||
|
|
|
|||
|
|
@ -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