web-humas-fe/components/page/sidebar-detail.tsx

175 lines
5.9 KiB
TypeScript
Raw Normal View History

"use client";
import React, { useEffect, useState } from "react";
import { UnderLine } from "../icons";
import { Autoplay, Pagination, Navigation, Mousewheel } from "swiper/modules";
import { Swiper, SwiperSlide } from "swiper/react";
import "swiper/css";
import "swiper/css/effect-fade";
import "swiper/css/pagination";
import Link from "next/link";
2025-05-04 07:14:12 +00:00
import { getListArticle } from "@/services/article";
import { Card, CardFooter, Skeleton } from "@heroui/react";
import { convertDateFormat, textEllipsis } from "@/utils/global";
2025-02-26 08:34:45 +00:00
import Image from "next/image";
2024-02-19 08:39:35 +00:00
export default function SidebarDetail() {
2025-05-19 03:33:49 +00:00
const [articleMabes, setArticleMabes] = useState<any>([]);
2025-05-31 19:00:00 +00:00
const [articlePolda, setArticlePolda] = useState<any>([]);
useEffect(() => {
2025-05-19 03:33:49 +00:00
getArticleMabes();
2025-05-31 19:00:00 +00:00
getArticlePolda();
}, []);
2025-05-19 03:33:49 +00:00
async function getArticleMabes() {
const req = {
page: 1,
search: "",
limit: "10",
isPublish: true,
2025-06-11 03:26:35 +00:00
category: "781,802",
};
2025-05-19 03:33:49 +00:00
const response = await getListArticle(req);
setArticleMabes(response?.data?.data);
2025-05-19 03:33:49 +00:00
}
2025-05-31 19:00:00 +00:00
async function getArticlePolda() {
2025-05-19 03:33:49 +00:00
const req = {
page: 1,
search: "",
limit: "10",
isPublish: true,
2025-06-09 09:41:54 +00:00
isPolda: true,
2025-05-19 03:33:49 +00:00
};
const response = await getListArticle(req);
2025-05-31 19:00:00 +00:00
setArticlePolda(response?.data?.data);
2025-05-19 03:33:49 +00:00
}
2025-05-31 19:00:00 +00:00
return (
<div className="mt-2 space-y-5">
2025-02-26 08:34:45 +00:00
<div className="font-semibold flex flex-col items-center py-3 rounded-lg">
<div className="flex flex-col items-center">
2025-02-26 08:34:45 +00:00
<div className="border-b-2 border-red-600 font-base text-lg">
Humas <span className="font-bold">MABES POLRI</span>
</div>
</div>
2025-02-26 08:34:45 +00:00
<div className="w-full mt-3">
{articleMabes?.length < 1 ? (
<Skeleton className="rounded-lg">
<div className="h-[320px] rounded-lg bg-default-300" />
</Skeleton>
) : (
<Swiper
centeredSlides={false}
spaceBetween={10}
mousewheel={true}
autoplay={{
delay: 5000,
disableOnInteraction: false,
}}
pagination={{
clickable: true,
}}
modules={[Autoplay, Pagination, Mousewheel]}
className="mySwiper"
slidesPerView={1}
>
{articleMabes?.map((newsItem: any) => (
<SwiperSlide key={newsItem.id}>
<div className=" h-[320px] flex flex-col gap-2 bg-gray-100 dark:bg-black p-4 rounded-lg">
<Image
width={480}
height={480}
alt="headernews"
src={
newsItem?.thumbnailUrl == ""
? "/no-image.jpg"
: newsItem?.thumbnailUrl
}
className="object-cover !h-[200px] rounded-lg"
/>
<div className="text-black dark:text-white flex flex-col">
<Link
href={`/news/detail/${newsItem.id}-${newsItem.slug}`}
>
<p className="text-left font-bold text-sm">
{textEllipsis(newsItem.title, 45)}
</p>
</Link>
<p className="py-[2px] text-left text-xs">
{convertDateFormat(newsItem.createdAt)} WIB
</p>
</div>
</div>
</SwiperSlide>
))}
</Swiper>
)}
</div>
</div>
<div className="font-semibold flex flex-col items-center space-y-5">
<div className="flex flex-col items-center">
2025-02-26 08:34:45 +00:00
<div className="border-b-2 border-red-600 font-base text-lg">
Humas <span className="font-bold">POLDA</span>
</div>
</div>
2025-02-26 08:34:45 +00:00
<div className="w-full mt-3">
2025-05-31 19:00:00 +00:00
{articlePolda?.length < 1 ? (
<Skeleton className="rounded-lg">
<div className="h-[320px] rounded-lg bg-default-300" />
</Skeleton>
) : (
<Swiper
centeredSlides={false}
spaceBetween={10}
mousewheel={true}
autoplay={{
delay: 5000,
disableOnInteraction: false,
}}
pagination={{
clickable: true,
}}
modules={[Autoplay, Pagination, Mousewheel]}
className="mySwiper"
slidesPerView={1}
>
2025-05-31 19:00:00 +00:00
{articlePolda?.map((newsItem: any) => (
<SwiperSlide key={newsItem.id}>
<div className=" h-[320px] flex flex-col gap-2 bg-gray-100 dark:bg-black p-4 rounded-lg">
<Image
width={480}
height={480}
alt="headernews"
src={
newsItem?.thumbnailUrl == ""
? "/no-image.jpg"
: newsItem?.thumbnailUrl
}
className="object-cover !h-[200px] rounded-lg"
/>
<div className="text-black dark:text-white flex flex-col">
<Link
href={`/news/detail/${newsItem.id}-${newsItem.slug}`}
>
<p className="text-left font-bold text-sm">
{textEllipsis(newsItem.title, 45)}
</p>
</Link>
<p className="py-[2px] text-left text-xs">
{convertDateFormat(newsItem.createdAt)} WIB
</p>
</div>
</div>
</SwiperSlide>
))}
</Swiper>
)}
2024-02-19 08:39:35 +00:00
</div>
</div>
</div>
);
2024-02-19 08:39:35 +00:00
}