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

190 lines
7.7 KiB
TypeScript
Raw Normal View History

2025-04-06 13:26:35 +00:00
import {
getCategoryData,
getPublicCategoryData,
} from "@/service/landing/landing";
2024-12-04 14:12:10 +00:00
import Link from "next/link";
2024-12-09 16:09:42 +00:00
import React, { useEffect, useState } from "react";
2024-12-13 14:33:59 +00:00
import { Button } from "../ui/button";
2024-12-17 14:27:48 +00:00
import { Reveal } from "./Reveal";
import { useTranslations } from "next-intl";
import { usePathname } from "next/navigation";
import { useParams } from "next/navigation";
2025-02-06 10:34:22 +00:00
import Image from "next/image";
2024-12-04 14:12:10 +00:00
const ContentCategory = (props: { group?: string }) => {
2024-12-09 16:09:42 +00:00
const [categories, setCategories] = useState<any>();
const t = useTranslations("LandingPage");
const params = useParams();
const locale = params?.locale;
const poldaName = params?.polda_name;
const satkerName = params?.satker_name;
2024-12-09 16:09:42 +00:00
useEffect(() => {
initFetch();
}, []);
const initFetch = async () => {
const response = await getPublicCategoryData(
2025-04-06 13:26:35 +00:00
props.group == "mabes"
? ""
: props.group == "polda" && poldaName && String(poldaName)?.length > 1
? poldaName
: props.group == "satker" &&
satkerName &&
String(satkerName)?.length > 1
? "satker-" + satkerName
: "",
"",
locale == "en" ? true : false
);
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);
const pathname = usePathname();
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-04-06 13:26:35 +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-03-28 07:50:51 +00:00
<div className="px-4 lg:px-24 py-10">
2024-12-17 14:27:48 +00:00
<Reveal>
2025-03-27 04:17:40 +00:00
<h2 className="bg-[#c03724] rounded-md p-3 w-fit text-white">
{/* {pathname?.split("/")[1] == "in" ? (
<>
<span className="text-black dark:text-white">{t("category")}&nbsp;</span>
{t("content")}
</>
) : (
<>
<span className="text-black dark:text-white">{t("content")}&nbsp;</span>
{t("category")}
</>
2025-03-27 04:17:40 +00:00
)} */}
Kategori Konten
2024-12-17 14:27:48 +00:00
</h2>
2025-03-27 04:17:40 +00:00
{/* <div className="h-1 w-48 bg-[#bb3523] mx-auto mb-6 rounded"></div> */}
2024-12-04 14:12:10 +00:00
2025-03-27 04:17:40 +00:00
<div className="grid my-8 grid-cols-1 lg:grid-cols-4 gap-4">
2024-12-17 14:27:48 +00:00
{categories?.map((category: any, index: number) =>
!seeAllValue ? (
2025-01-31 12:51:04 +00:00
index < 4 ? (
// <Link key={category?.id} href={`all/filter?category=${category?.id}`} className="relative group rounded-md overflow-hidden shadow-md hover:shadow-lg">
// <Image
// placeholder={`data:image/svg+xml;base64,${toBase64(shimmer(700, 475))}`}
// alt="category"
// width={2560}
// height={1440}
// src={category?.thumbnailLink}
// className="w-full lg:w-[315px] lg:h-[250px] h-40 object-cover group-hover:scale-110 transition-transform duration-300"
// />
// <div className="absolute bottom-5 left-0 right-16 bg-transparent backdrop-blur-md text-white p-4 border-l-2 border-[#bb3523]">
// <h3 className="text-sm font-semibold truncate">{category?.name}</h3>
// </div>
// </Link>
2025-04-06 13:26:35 +00:00
<Link
key={category?.id}
href={`all/filter?category=${category?.id}`}
className="relative group rounded-md overflow-hidden shadow-md hover:shadow-lg"
>
{/* Gambar */}
2025-03-27 04:17:40 +00:00
<Image
2025-04-06 13:26:35 +00:00
placeholder={`data:image/svg+xml;base64,${toBase64(
shimmer(700, 475)
)}`}
2025-03-27 04:17:40 +00:00
alt="category"
width={2560}
height={1440}
src={category?.thumbnailLink}
2025-03-28 07:50:51 +00:00
className="w-full lg:h-[250px] h-40 object-cover group-hover:scale-110 transition-transform duration-300"
2025-03-27 04:17:40 +00:00
/>
{/* Overlay gelap */}
<div className="absolute inset-0 bg-black bg-opacity-25 group-hover:bg-opacity-35 transition-all duration-300 rounded-md"></div>
{/* Judul */}
2025-04-06 13:26:35 +00:00
<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>
2024-12-17 14:27:48 +00:00
</div>
</Link>
) : (
""
)
) : (
// <Link key={category?.id} href={`all/filter?category=${category?.id}`} className="relative group rounded-md overflow-hidden shadow-md hover:shadow-lg">
// <Image
// placeholder={`data:image/svg+xml;base64,${toBase64(shimmer(700, 475))}`}
// alt="category"
// width={2560}
// height={1440}
// src={category?.thumbnailLink}
// className="w-fulllg:w-[315px] lg:h-[250px] h-40 object-cover group-hover:scale-110 transition-transform duration-300"
// />
// <div className="absolute bottom-5 left-0 right-16 bg-transparent backdrop-blur-md text-white p-4 border-l-2 border-[#bb3523]">
// <h3 className="text-sm font-semibold truncate">{category?.name}</h3>
// </div>
// </Link>
2025-04-06 13:26:35 +00:00
<Link
key={category?.id}
href={`all/filter?category=${category?.id}`}
className="relative group rounded-md overflow-hidden shadow-md hover:shadow-lg"
>
{/* Gambar */}
2025-03-27 04:17:40 +00:00
<Image
2025-04-06 13:26:35 +00:00
placeholder={`data:image/svg+xml;base64,${toBase64(
shimmer(700, 475)
)}`}
2025-03-27 04:17:40 +00:00
alt="category"
width={2560}
height={1440}
src={category?.thumbnailLink}
2025-03-28 07:50:51 +00:00
className="w-full lg:h-[250px] h-40 object-cover group-hover:scale-110 transition-transform duration-300"
2025-03-27 04:17:40 +00:00
/>
{/* Overlay Gelap */}
<div className="absolute inset-0 bg-black bg-opacity-25 group-hover:bg-opacity-35 transition-all duration-300"></div>
{/* 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">
2025-04-06 13:26:35 +00:00
<h3 className="text-sm font-semibold truncate">
{category?.name}
</h3>
2024-12-13 14:33:59 +00:00
</div>
</Link>
)
2024-12-17 14:27:48 +00:00
)}
</div>
<div className="flex items-center flex-row justify-center">
2025-04-06 13:26:35 +00:00
<Button
onClick={() => setSeeAllValue(!seeAllValue)}
className="bg-white hover:bg-[#bb3523] text-[#bb3523] hover:text-white border-2 border-[#bb3523]"
>
{seeAllValue ? t("seeLess") : t("seeMore")}
2024-12-17 14:27:48 +00:00
</Button>
</div>
</Reveal>
2024-12-04 14:12:10 +00:00
</div>
);
};
export default ContentCategory;