2024-12-09 16:09:42 +00:00
|
|
|
import { getCategoryData } 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";
|
2025-01-05 13:46:18 +00:00
|
|
|
import { useTranslations } from "next-intl";
|
|
|
|
|
import { usePathname } from "next/navigation";
|
2024-12-04 14:12:10 +00:00
|
|
|
|
|
|
|
|
const ContentCategory = () => {
|
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");
|
|
|
|
|
|
2024-12-09 16:09:42 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
initFetch();
|
|
|
|
|
}, []);
|
|
|
|
|
const initFetch = async () => {
|
|
|
|
|
const response = await getCategoryData();
|
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();
|
|
|
|
|
console.log("split", pathname);
|
2024-12-04 14:12:10 +00:00
|
|
|
return (
|
2024-12-11 15:08:03 +00:00
|
|
|
<div className="mx-auto px-4 lg:px-20 py-10 max-w-screen-2xl ">
|
2024-12-17 14:27:48 +00:00
|
|
|
<Reveal>
|
|
|
|
|
<h2 className="text-center text-xl lg:text-2xl font-bold text-[#bb3523] mb-4">
|
2025-01-05 13:46:18 +00:00
|
|
|
{pathname?.split("/")[1] == "in" ? (
|
|
|
|
|
<>
|
|
|
|
|
<span className="text-black dark:text-white">{t("category")} </span>
|
|
|
|
|
{t("content")}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<span className="text-black dark:text-white">{t("content")} </span>
|
|
|
|
|
{t("category")}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-12-17 14:27:48 +00:00
|
|
|
</h2>
|
|
|
|
|
<div className="h-1 w-48 bg-[#bb3523] mx-auto mb-6 rounded"></div>
|
2024-12-04 14:12:10 +00:00
|
|
|
|
2024-12-17 14:27:48 +00:00
|
|
|
<div className="grid my-3 grid-cols-2 lg:grid-cols-4 gap-4">
|
|
|
|
|
{categories?.map((category: any, index: number) =>
|
|
|
|
|
!seeAllValue ? (
|
|
|
|
|
index < 8 ? (
|
|
|
|
|
<Link key={category?.id} href={`all/filter?category=${category?.id}`} className="relative group rounded-md overflow-hidden shadow-md hover:shadow-lg">
|
|
|
|
|
<img src={category?.thumbnailLink} className="w-full h-48 sm:h-40 object-cover group-hover:scale-110 transition-transform duration-300" />
|
2024-12-18 16:28:31 +00:00
|
|
|
<div className="absolute bottom-0 rounded-lg left-0 right-0 bg-gray-400 border-l-4 mb-4 border-[#bb3523] text-white p-2">
|
2024-12-17 14:27:48 +00:00
|
|
|
<h3 className="text-sm font-semibold truncate">{category?.name}</h3>
|
|
|
|
|
</div>
|
|
|
|
|
</Link>
|
|
|
|
|
) : (
|
|
|
|
|
""
|
|
|
|
|
)
|
|
|
|
|
) : (
|
2024-12-13 14:33:59 +00:00
|
|
|
<Link key={category?.id} href={`all/filter?category=${category?.id}`} className="relative group rounded-md overflow-hidden shadow-md hover:shadow-lg">
|
|
|
|
|
<img src={category?.thumbnailLink} className="w-full h-48 sm:h-40 object-cover group-hover:scale-110 transition-transform duration-300" />
|
2024-12-18 16:28:31 +00:00
|
|
|
<div className="absolute bottom-0 left-0 right-0 bg-gray-400 border-l-4 mb-4 border-[#bb3523] rounded-lg text-white p-2">
|
2024-12-13 14:33:59 +00:00
|
|
|
<h3 className="text-sm font-semibold truncate">{category?.name}</h3>
|
|
|
|
|
</div>
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
2024-12-17 14:27:48 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center flex-row justify-center">
|
|
|
|
|
<Button onClick={() => setSeeAllValue(!seeAllValue)} className="bg-white hover:bg-[#bb3523] text-[#bb3523] hover:text-white border-2 border-[#bb3523]">
|
2025-01-05 13:46:18 +00:00
|
|
|
{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;
|