2025-06-02 01:00:01 +00:00
|
|
|
import { getCategoryData, getPublicCategoryData } from "@/service/landing/landing";
|
2024-12-09 16:09:42 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2024-12-17 14:27:48 +00:00
|
|
|
import { Reveal } from "./Reveal";
|
2025-01-05 13:46:18 +00:00
|
|
|
import { useTranslations } from "next-intl";
|
|
|
|
|
import { usePathname } from "next/navigation";
|
2025-01-13 00:35:40 +00:00
|
|
|
import { useParams } from "next/navigation";
|
2025-02-06 10:34:22 +00:00
|
|
|
import Image from "next/image";
|
2025-06-02 01:00:01 +00:00
|
|
|
import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "../ui/carousel";
|
2025-04-24 11:50:48 +00:00
|
|
|
import { useRouter } from "@/i18n/routing";
|
2025-05-06 10:03:46 +00:00
|
|
|
import { Button } from "../ui/button";
|
2024-12-04 14:12:10 +00:00
|
|
|
|
2025-05-05 14:53:47 +00:00
|
|
|
const ContentCategory = (props: { group?: string; type: string }) => {
|
2024-12-09 16:09:42 +00:00
|
|
|
const [categories, setCategories] = useState<any>();
|
2025-01-05 13:46:18 +00:00
|
|
|
const t = useTranslations("LandingPage");
|
2025-01-13 00:35:40 +00:00
|
|
|
const params = useParams();
|
|
|
|
|
const locale = params?.locale;
|
2025-05-05 14:53:47 +00:00
|
|
|
const [selectedTab, setSelectedTab] = useState("image");
|
2025-01-13 00:35:40 +00:00
|
|
|
const poldaName = params?.polda_name;
|
|
|
|
|
const satkerName = params?.satker_name;
|
2025-04-24 11:50:48 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
|
2025-06-02 01:00:01 +00:00
|
|
|
let prefixPath = poldaName ? `/polda/${poldaName}` : satkerName ? `/satker/${satkerName}` : "/";
|
2025-01-05 13:46:18 +00:00
|
|
|
|
2024-12-09 16:09:42 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
initFetch();
|
|
|
|
|
}, []);
|
|
|
|
|
const initFetch = async () => {
|
2025-01-13 00:35:40 +00:00
|
|
|
const response = await getPublicCategoryData(
|
2025-06-02 01:00:01 +00:00
|
|
|
props.group == "mabes" ? "" : props.group == "polda" && poldaName && String(poldaName)?.length > 1 ? poldaName : props.group == "satker" && satkerName && String(satkerName)?.length > 1 ? "satker-" + satkerName : "",
|
2025-01-13 00:35:40 +00:00
|
|
|
"",
|
|
|
|
|
locale == "en" ? true : false
|
|
|
|
|
);
|
2024-12-10 13:51:14 +00:00
|
|
|
console.log("category", response);
|
2024-12-09 16:09:42 +00:00
|
|
|
setCategories(response?.data?.data?.content);
|
|
|
|
|
};
|
2024-12-04 14:12:10 +00:00
|
|
|
|
2024-12-11 15:08:03 +00:00
|
|
|
const [searchTerm, setSearchTerm] = useState("");
|
|
|
|
|
const [seeAllValue, setSeeAllValue] = useState(false);
|
2025-01-05 13:46:18 +00:00
|
|
|
const pathname = usePathname();
|
2025-01-06 14:36:37 +00:00
|
|
|
|
2025-03-07 12:32:47 +00:00
|
|
|
const shimmer = (w: number, h: number) => `
|
|
|
|
|
<svg width="${w}" height="${h}" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
|
|
|
<defs>
|
|
|
|
|
<linearGradient id="g">
|
|
|
|
|
<stop stop-color="#bcbcbd" offset="20%" />
|
|
|
|
|
<stop stop-color="#f9fafb" offset="50%" />
|
|
|
|
|
<stop stop-color="#bcbcbd" offset="70%" />
|
|
|
|
|
</linearGradient>
|
|
|
|
|
</defs>
|
|
|
|
|
<rect width="${w}" height="${h}" fill="#bcbcbd" />
|
|
|
|
|
<rect id="r" width="${w}" height="${h}" fill="url(#g)" />
|
|
|
|
|
<animate xlink:href="#r" attributeName="x" from="-${w}" to="${w}" dur="1s" repeatCount="indefinite" />
|
|
|
|
|
</svg>`;
|
2025-03-27 04:17:40 +00:00
|
|
|
|
2025-06-02 01:00:01 +00:00
|
|
|
const toBase64 = (str: string) => (typeof window === "undefined" ? Buffer.from(str).toString("base64") : window.btoa(str));
|
2025-03-07 12:32:47 +00:00
|
|
|
|
2024-12-04 14:12:10 +00:00
|
|
|
return (
|
2025-06-02 06:11:34 +00:00
|
|
|
<div className="px-4 lg:px-0 py-10">
|
2024-12-17 14:27:48 +00:00
|
|
|
<Reveal>
|
2025-06-02 06:11:34 +00:00
|
|
|
<div className="flex flex-col">
|
2025-05-21 15:06:56 +00:00
|
|
|
<h2 className="text-start text-lg md:text-xl font-bold text-[#bb3523] border-b-2 border-[#bb3523] mb-4 uppercase">
|
|
|
|
|
{pathname?.split("/")[1] == "in" ? (
|
|
|
|
|
<>
|
2025-06-02 01:00:01 +00:00
|
|
|
<span className="text-[#bb3523] dark:text-white">{t("category")} </span>
|
2025-05-21 15:06:56 +00:00
|
|
|
{t("content")}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2025-06-02 01:00:01 +00:00
|
|
|
<span className="text-[#bb3523] dark:text-white">{t("content")} </span>
|
2025-05-21 15:06:56 +00:00
|
|
|
{t("category")}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</h2>
|
|
|
|
|
<div className="grid grid-cols-2 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
2025-06-02 01:00:01 +00:00
|
|
|
{(seeAllValue ? categories : categories?.slice(0, 8))?.map((category: any) => (
|
|
|
|
|
<div key={category?.id}>
|
|
|
|
|
<div onClick={() => router.push(`${prefixPath}all/filter?category=${category?.id}`)} className="cursor-pointer relative group rounded-md overflow-hidden shadow-md hover:shadow-lg block">
|
|
|
|
|
{/* Gambar */}
|
|
|
|
|
<Image
|
|
|
|
|
placeholder={`data:image/svg+xml;base64,${toBase64(shimmer(700, 475))}`}
|
|
|
|
|
alt="category"
|
|
|
|
|
width={2560}
|
|
|
|
|
height={1440}
|
|
|
|
|
src={category?.thumbnailLink}
|
|
|
|
|
className="w-full lg:h-[300px] h-40 object-cover group-hover:scale-110 transition-transform duration-300"
|
|
|
|
|
/>
|
2025-03-27 14:00:01 +00:00
|
|
|
|
2025-06-02 01:00:01 +00:00
|
|
|
{/* Overlay gelap */}
|
|
|
|
|
<div className="absolute inset-0 bg-black bg-opacity-50 group-hover:bg-opacity-35 transition-all duration-300 rounded-md"></div>
|
2025-03-27 14:00:01 +00:00
|
|
|
|
2025-06-02 01:00:01 +00:00
|
|
|
{/* Judul */}
|
|
|
|
|
<div className="absolute bottom-5 left-1/2 transform -translate-x-1/2 text-white">
|
|
|
|
|
<h3 className="text-sm font-semibold text-center">{category?.name}</h3>
|
2025-05-20 07:08:49 +00:00
|
|
|
</div>
|
2025-05-06 10:03:46 +00:00
|
|
|
</div>
|
2025-06-02 01:00:01 +00:00
|
|
|
</div>
|
|
|
|
|
))}
|
2025-05-06 10:03:46 +00:00
|
|
|
</div>
|
|
|
|
|
|
2025-05-21 15:06:56 +00:00
|
|
|
{/* Tombol See More / See Less */}
|
|
|
|
|
{categories?.length > 8 && (
|
|
|
|
|
<div className="flex items-center flex-row justify-center mt-6">
|
2025-06-02 01:00:01 +00:00
|
|
|
<Button onClick={() => setSeeAllValue(!seeAllValue)} className="bg-white hover:bg-[#bb3523] text-[#bb3523] hover:text-white border-2 border-[#bb3523]">
|
2025-05-21 15:06:56 +00:00
|
|
|
{seeAllValue ? t("seeLess") : t("seeMore")}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* <div className="flex items-center flex-row justify-center mt-7">
|
2025-04-24 11:50:48 +00:00
|
|
|
<div
|
2025-05-05 14:53:47 +00:00
|
|
|
onClick={() =>
|
|
|
|
|
router.push(
|
|
|
|
|
prefixPath + `/${selectedTab}/filter?sortBy=${props.type}`
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-04-24 11:50:48 +00:00
|
|
|
className="cursor-pointer border text-[#bb3523] rounded-lg text-sm lg:text-md px-4 py-1 border-[#bb3523]"
|
|
|
|
|
>
|
|
|
|
|
{t("seeAll")}
|
|
|
|
|
</div>
|
2025-05-06 10:03:46 +00:00
|
|
|
</div> */}
|
2025-05-21 15:06:56 +00:00
|
|
|
</div>
|
2024-12-17 14:27:48 +00:00
|
|
|
</Reveal>
|
2024-12-04 14:12:10 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ContentCategory;
|