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