update
This commit is contained in:
parent
3cf1334aeb
commit
5ada3e1433
|
|
@ -0,0 +1,18 @@
|
|||
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 { CommentIcon } from "../icons/sidebar-icon";
|
||||
|
|
@ -16,6 +20,7 @@ import {
|
|||
postArticleComment,
|
||||
} from "@/service/master-user";
|
||||
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);
|
||||
|
|
@ -252,8 +259,8 @@ 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);
|
||||
|
|
@ -524,9 +531,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>
|
||||
)}
|
||||
|
|
@ -696,7 +711,7 @@ export default function DetailContent() {
|
|||
<div>
|
||||
<Link
|
||||
className="flex space-x-3 mb-2"
|
||||
href={`/detail/${article.id}`}
|
||||
href={`/details/${article.slug}`}
|
||||
>
|
||||
<Image
|
||||
src={article.thumbnailUrl || "/default-thumb.png"}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -52,7 +53,7 @@ export default function HeadersAchievment() {
|
|||
<div className="px-4 py-6">
|
||||
{/* Featured Article */}
|
||||
<div className="relative w-full h-[400px] mb-4 rounded-lg overflow-hidden">
|
||||
<Link href={`/detail/${featured?.id}`}>
|
||||
<Link href={`/details/${featured?.slug}`}>
|
||||
<Image
|
||||
src={featured?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
alt={featured?.title}
|
||||
|
|
@ -74,7 +75,7 @@ export default function HeadersAchievment() {
|
|||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||
{others.map((item) => (
|
||||
<div key={item.id} className="relative rounded overflow-hidden">
|
||||
<Link href={`/detail/${item?.id}`}>
|
||||
<Link href={`/details/${item?.slug}`}>
|
||||
<div className="w-full h-[180px] relative">
|
||||
<Image
|
||||
src={item?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -52,7 +53,7 @@ export default function HeadersActivity() {
|
|||
<div className="px-4 py-6">
|
||||
{/* Featured Article */}
|
||||
<div className="relative w-full h-[400px] mb-4 rounded-lg overflow-hidden">
|
||||
<Link href={`/detail/${featured?.id}`}>
|
||||
<Link href={`/details/${featured?.slug}`}>
|
||||
<Image
|
||||
src={featured?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
alt={featured?.title}
|
||||
|
|
@ -74,7 +75,7 @@ export default function HeadersActivity() {
|
|||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||
{others.map((item) => (
|
||||
<div key={item.id} className="relative rounded overflow-hidden">
|
||||
<Link href={`/detail/${item?.id}`}>
|
||||
<Link href={`/details/${item?.slug}`}>
|
||||
<div className="w-full h-[180px] relative">
|
||||
<Image
|
||||
src={item?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ type Article = {
|
|||
title: string;
|
||||
description: string;
|
||||
categoryName: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
|
|
@ -51,7 +52,7 @@ export default function HeadersOpini() {
|
|||
return (
|
||||
<div className="px-4 py-6">
|
||||
<div className="relative w-full h-[400px] mb-4 rounded-lg overflow-hidden">
|
||||
<Link href={`/detail/${featured?.id}`}>
|
||||
<Link href={`/details/${featured?.slug}`}>
|
||||
<Image
|
||||
src={featured?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
alt={featured?.title}
|
||||
|
|
@ -72,7 +73,7 @@ export default function HeadersOpini() {
|
|||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||
{others.map((item) => (
|
||||
<div key={item.id} className="relative rounded overflow-hidden">
|
||||
<Link href={`/detail/${item?.id}`}>
|
||||
<Link href={`/details/${item?.slug}`}>
|
||||
<div className="w-full h-[180px] relative">
|
||||
<Image
|
||||
src={item?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ type Article = {
|
|||
description: string;
|
||||
categoryName: string;
|
||||
createdAt: string;
|
||||
slug: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
categories: {
|
||||
|
|
@ -90,7 +91,7 @@ export default function Beranda() {
|
|||
<div key={article.id}>
|
||||
<Link
|
||||
className="flex-shrink-0 flex items-start gap-3 w-[350px]"
|
||||
href={`/detail/${article?.id}`}
|
||||
href={`/details/${article?.slug}`}
|
||||
>
|
||||
<Image
|
||||
src={article.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ type Article = {
|
|||
categoryName: string;
|
||||
createdAt: string;
|
||||
createdByName: string;
|
||||
slug: string;
|
||||
thumbnailUrl: string;
|
||||
categories: {
|
||||
title: string;
|
||||
|
|
@ -51,7 +52,7 @@ export default function HeadersInspiration() {
|
|||
return (
|
||||
<div className="px-4 py-6">
|
||||
<div className="relative w-full h-[400px] mb-4 rounded-lg overflow-hidden">
|
||||
<Link href={`/detail/${featured?.id}`}>
|
||||
<Link href={`/details/${featured?.slug}`}>
|
||||
<Image
|
||||
src={featured?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
alt={featured?.title}
|
||||
|
|
@ -72,7 +73,7 @@ export default function HeadersInspiration() {
|
|||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||
{others.map((item) => (
|
||||
<div key={item.id} className="relative rounded overflow-hidden">
|
||||
<Link href={`/detail/${item?.id}`}>
|
||||
<Link href={`/details/${item?.slug}`}>
|
||||
<div className="w-full h-[180px] relative">
|
||||
<Image
|
||||
src={item?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ type Article = {
|
|||
createdAt: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
slug: string;
|
||||
categories: {
|
||||
title: string;
|
||||
}[];
|
||||
|
|
@ -122,7 +123,7 @@ export default function News() {
|
|||
</div>
|
||||
|
||||
<div className="flex-1">
|
||||
<Link href={`/detail/${item.id}`}>
|
||||
<Link href={`/details/${item.slug}`}>
|
||||
<h3 className="font-semibold text-xl font-serif mb-2 cursor-pointer hover:text-green-700">
|
||||
{item.title}
|
||||
</h3>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ type Article = {
|
|||
id: number;
|
||||
title: string;
|
||||
createdAt: string;
|
||||
slug: string;
|
||||
thumbnailUrl?: string;
|
||||
categories: Category[];
|
||||
};
|
||||
|
|
@ -52,7 +53,7 @@ function NewsColumn({ title, color, items }: NewsColumnProps) {
|
|||
className={`flex flex-col ${
|
||||
index === 0 ? "md:flex-row" : ""
|
||||
} border-b border-gray-200 pb-3`}
|
||||
href={`/detail/${item?.id}`}
|
||||
href={`/details/${item?.slug}`}
|
||||
>
|
||||
{index === 0 && item?.thumbnailUrl && (
|
||||
<div className="w-full md:w-40 h-24 relative mr-3">
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ type Article = {
|
|||
description: string;
|
||||
categoryName: string;
|
||||
createdAt: string;
|
||||
slug: string;
|
||||
createdByName: string;
|
||||
thumbnailUrl: string;
|
||||
categories: {
|
||||
|
|
@ -51,7 +52,7 @@ export default function HeadersService() {
|
|||
return (
|
||||
<div className="px-4 py-6">
|
||||
<div className="relative w-full h-[400px] mb-4 rounded-lg overflow-hidden">
|
||||
<Link href={`/detail/${featured?.id}`}>
|
||||
<Link href={`/details/${featured?.slug}`}>
|
||||
<Image
|
||||
src={featured?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
alt={featured?.title}
|
||||
|
|
@ -72,7 +73,7 @@ export default function HeadersService() {
|
|||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||
{others.map((item) => (
|
||||
<div key={item.id} className="relative rounded overflow-hidden">
|
||||
<Link href={`/detail/${item?.id}`}>
|
||||
<Link href={`/details/${item?.slug}`}>
|
||||
<div className="w-full h-[180px] relative">
|
||||
<Image
|
||||
src={item?.thumbnailUrl || "/default-thumbnail.jpg"}
|
||||
|
|
|
|||
|
|
@ -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