mediahub-fe/components/landing-page/landing-polda-kaltara/content-category-kaltara.tsx

156 lines
6.0 KiB
TypeScript
Raw Permalink Normal View History

2025-05-06 10:03:46 +00:00
import {
getCategoryData,
getPublicCategoryData,
} from "@/service/landing/landing";
2025-03-24 17:22:16 +00:00
import React, { useEffect, useState } from "react";
import { useTranslations } from "next-intl";
import { usePathname } from "next/navigation";
import { useParams } from "next/navigation";
import Image from "next/image";
2025-05-06 10:03:46 +00:00
import { useRouter } from "@/i18n/routing";
2025-03-24 17:22:16 +00:00
import { Reveal } from "../Reveal";
2025-05-06 10:03:46 +00:00
import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "@/components/ui/carousel";
2025-03-24 17:22:16 +00:00
2025-05-06 10:03:46 +00:00
const ContentCategoryKaltara = (props: { group?: string; type: string }) => {
2025-03-24 17:22:16 +00:00
const [categories, setCategories] = useState<any>();
const t = useTranslations("LandingPage");
const params = useParams();
const locale = params?.locale;
2025-05-06 10:03:46 +00:00
const [selectedTab, setSelectedTab] = useState("image");
2025-03-24 17:22:16 +00:00
const poldaName = params?.polda_name;
const satkerName = params?.satker_name;
2025-05-06 10:03:46 +00:00
const router = useRouter();
let prefixPath = poldaName
? `/polda/${poldaName}`
: satkerName
? `/satker/${satkerName}`
: "/";
2025-03-24 17:22:16 +00:00
useEffect(() => {
initFetch();
}, []);
const initFetch = async () => {
const response = await getPublicCategoryData(
2025-05-06 10:03:46 +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-03-24 17:22:16 +00:00
"",
locale == "en" ? true : false
);
console.log("category", response);
setCategories(response?.data?.data?.content);
};
2025-05-06 10:03:46 +00:00
const [searchTerm, setSearchTerm] = useState("");
const [seeAllValue, setSeeAllValue] = useState(false);
const pathname = usePathname();
2025-03-24 17:22:16 +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-05-06 10:03:46 +00:00
const toBase64 = (str: string) =>
typeof window === "undefined"
? Buffer.from(str).toString("base64")
: window.btoa(str);
2025-03-24 17:22:16 +00:00
return (
2025-06-09 06:09:47 +00:00
<div className="px-4 lg:px-[115px] py-10">
2025-03-24 17:22:16 +00:00
<Reveal>
2025-05-06 10:03:46 +00:00
<h2 className="text-center text-xl lg:text-3xl font-bold text-[#bb3523] mb-4">
2025-03-24 17:22:16 +00:00
{pathname?.split("/")[1] == "in" ? (
<>
2025-05-06 10:03:46 +00:00
<span className="text-black dark:text-white">
{t("category", { defaultValue: "Category" })}&nbsp;
2025-05-06 10:03:46 +00:00
</span>
{t("content", { defaultValue: "Content" })}
2025-03-24 17:22:16 +00:00
</>
) : (
<>
2025-05-06 10:03:46 +00:00
<span className="text-black dark:text-white">
{t("content", { defaultValue: "Content" })}&nbsp;
2025-05-06 10:03:46 +00:00
</span>
{t("category", { defaultValue: "Category" })}
2025-03-24 17:22:16 +00:00
</>
)}
</h2>
2025-05-06 10:03:46 +00:00
<div className="h-1 w-52 bg-[#bb3523] mx-auto mb-6 rounded"></div>
<div className="">
<Carousel className="w-full max-w-full">
<CarouselContent>
{categories?.map((category: any) => (
<CarouselItem key={category?.id} className="md:basis-1/2 lg:basis-1/3">
<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
2025-07-06 14:57:09 +00:00
priority={true}
2025-05-06 10:03:46 +00:00
placeholder={`data:image/svg+xml;base64,${toBase64(
shimmer(700, 475)
)}`}
alt="category"
width={2560}
height={1440}
2025-07-06 19:20:22 +00:00
src={category?.smallThumbnailLink}
2025-05-06 10:03:46 +00:00
className="w-full lg:h-[250px] h-40 object-cover group-hover:scale-110 transition-transform duration-300"
/>
{/* Overlay gelap */}
<div className="absolute inset-0 bg-black bg-opacity-25 group-hover:bg-opacity-35 transition-all duration-300 rounded-md"></div>
2025-03-24 17:22:16 +00:00
2025-05-06 10:03:46 +00:00
{/* Judul */}
<div className="absolute bottom-5 left-0 right-16 bg-transparent backdrop-blur-md text-white p-4 border-l-2 border-[#bb3523] z-10 group-hover:scale-x-150 origin-left">
<h3 className="text-sm font-semibold truncate">
{category?.name}
</h3>
</div>
2025-03-24 17:22:16 +00:00
</div>
2025-05-06 10:03:46 +00:00
</CarouselItem>
))}
</CarouselContent>
<CarouselPrevious className="-ml-0 lg:-ml-7" />
<CarouselNext className="-mr-0 lg:-mr-7" />
</Carousel>
2025-03-24 17:22:16 +00:00
</div>
2025-05-06 10:03:46 +00:00
{/* <div className="flex items-center flex-row justify-center">
2025-03-24 17:22:16 +00:00
<Button onClick={() => setSeeAllValue(!seeAllValue)} className="bg-white hover:bg-[#bb3523] text-[#bb3523] hover:text-white border-2 border-[#bb3523]">
{seeAllValue ? t("seeLess", { defaultValue: "See Less" }) : t("seeMore", { defaultValue: "See More" })}
2025-03-24 17:22:16 +00:00
</Button>
2025-05-06 10:03:46 +00:00
</div> */}
<div className="flex items-center flex-row justify-center mt-7">
<div
onClick={() =>
router.push(
prefixPath + `/${selectedTab}/filter?sortBy=${props.type}`
)
}
className="cursor-pointer border text-[#bb3523] rounded-lg text-sm lg:text-md px-4 py-1 border-[#bb3523]"
>
{t("seeAll", { defaultValue: "See All" })}
2025-05-06 10:03:46 +00:00
</div>
2025-03-24 17:22:16 +00:00
</div>
</Reveal>
</div>
);
};
2025-05-06 10:03:46 +00:00
export default ContentCategoryKaltara;