mediahub-fe/app/[locale]/(public)/indeks/page.tsx

256 lines
11 KiB
TypeScript
Raw Normal View History

2024-12-03 15:05:13 +00:00
"use client";
2025-01-24 15:56:24 +00:00
import { Skeleton } from "@/components/ui/skeleton";
import { Link } from "@/i18n/routing";
2024-12-12 15:27:00 +00:00
import { getIndeksData } from "@/service/landing/landing";
2025-04-07 16:37:19 +00:00
import { formatDateToIndonesian, htmlToString } from "@/utils/globals";
2025-02-06 10:34:22 +00:00
import Image from "next/image";
2024-12-03 15:05:13 +00:00
import { usePathname } from "next/navigation";
2024-12-12 15:27:00 +00:00
import React, { useEffect, useState } from "react";
2024-12-03 15:05:13 +00:00
2024-12-12 15:27:00 +00:00
const Indeks: React.FC = () => {
2024-12-03 15:05:13 +00:00
const pathname = usePathname();
2025-01-24 15:56:24 +00:00
const [isLoading, setIsLoading] = useState<any>(true);
2024-12-12 15:27:00 +00:00
const [indeksData, setIndeksData] = useState<any>();
2024-12-13 14:33:59 +00:00
let count: number = 0;
useEffect(() => {
if (indeksData) {
const intervalId = setInterval(() => {
count = (count + 1) % indeksData.length;
}, 5000);
return () => clearInterval(intervalId);
}
}, [indeksData]);
2025-01-24 15:56:24 +00:00
useEffect(() => {
const timer = setTimeout(() => {
setIsLoading(false);
}, 3000);
return () => clearTimeout(timer);
}, []);
2024-12-12 15:27:00 +00:00
useEffect(() => {
initFetch();
}, []);
const initFetch = async () => {
const response = await getIndeksData();
console.log(response);
setIndeksData(response?.data?.data?.content);
};
2024-12-03 15:05:13 +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-04-07 16:37:19 +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-03 15:05:13 +00:00
return (
2024-12-12 15:27:00 +00:00
<div className="px-4 lg:px-14">
{/* Hero Left */}
<div className="flex flex-col lg:flex-row items-start gap-8 px-4 lg:px-10 py-4 mx-auto">
2025-01-24 15:56:24 +00:00
{isLoading ? (
<div className="flex flex-col space-y-3 mx-auto w-full lg:w-2/3">
<Skeleton className="h-[310px] lg:h-[420px] rounded-xl" />
</div>
) : (
<div className="lg:w-[60%] w-full lg:h-full">
{indeksData?.map(
(indeks: any, index: number) =>
index == count && (
2025-04-07 16:37:19 +00:00
<div
key={indeks?.id}
className="relative h-[310px] lg:h-[435px]"
>
<Image
placeholder={`data:image/svg+xml;base64,${toBase64(
shimmer(700, 475)
)}`}
width={2560}
height={1440}
src={indeks?.thumbnailLink}
alt="image"
className="w-full h-[310px] lg:h-[435px] rounded-lg object-cover"
/>
<div className="absolute bottom-0 left-0 right-0 bg-black/15 backdrop-brightness-50 text-white p-4 rounded-b-lg">
<span className="text-white bg-[#bb3523] rounded-md w-full h-full font-semibold uppercase text-xs px-2 py-1">
{indeks?.categoryName}
</span>
2025-01-24 15:56:24 +00:00
<Link href={`/indeks/detail/${indeks?.slug}`}>
2025-04-07 16:37:19 +00:00
<h2 className="text-2xl font-bold mt-2">
{indeks?.title}
</h2>
2025-01-24 15:56:24 +00:00
</Link>
2025-02-06 10:34:22 +00:00
<p className="text-xs flex flex-row items-center gap-1 mt-1">
2025-04-07 16:37:19 +00:00
{formatDateToIndonesian(new Date(indeks?.createdAt))}{" "}
{indeks?.timezone ? indeks?.timezone : "WIB"} |{" "}
{/* <svg
xmlns="http://www.w3.org/2000/svg"
width="1.2em"
height="1.2em"
viewBox="0 0 24 24"
>
2025-01-24 15:56:24 +00:00
<path
fill="currentColor"
d="M11.5 18c4 0 7.46-2.22 9.24-5.5C18.96 9.22 15.5 7 11.5 7s-7.46 2.22-9.24 5.5C4.04 15.78 7.5 18 11.5 18m0-12c4.56 0 8.5 2.65 10.36 6.5C20 16.35 16.06 19 11.5 19S3 16.35 1.14 12.5C3 8.65 6.94 6 11.5 6m0 2C14 8 16 10 16 12.5S14 17 11.5 17S7 15 7 12.5S9 8 11.5 8m0 1A3.5 3.5 0 0 0 8 12.5a3.5 3.5 0 0 0 3.5 3.5a3.5 3.5 0 0 0 3.5-3.5A3.5 3.5 0 0 0 11.5 9"
/>
2025-04-07 16:37:19 +00:00
</svg>{" "} */}
{/* {indeks?.clickCount} */}
2025-01-24 15:56:24 +00:00
</p>
</div>
2024-12-13 14:33:59 +00:00
</div>
2025-01-24 15:56:24 +00:00
)
)}
</div>
)}
2024-12-12 15:27:00 +00:00
{/* Hero Right */}
2024-12-13 14:33:59 +00:00
<div className="lg:w-[40%] w-full space-y-2">
2025-01-24 15:56:24 +00:00
{isLoading ? (
<>
<div className="flex flex-col space-y-3 w-full justify-center items-center gap-3">
2025-01-31 12:51:04 +00:00
<Skeleton className="h-[200px] w-full lg:w-[400px] rounded-xl" />
<Skeleton className="h-[200px] w-full lg:w-[400px] rounded-xl" />
2025-01-24 15:56:24 +00:00
</div>
</>
) : (
<>
{indeksData?.map(
(indeksRight: any, index: number) =>
(index == count + 1 || index == count + 2) && (
2025-04-07 16:37:19 +00:00
<div
key={indeksRight?.id}
className="relative h-[310px] lg:h-[215px]"
>
<Image
placeholder={`data:image/svg+xml;base64,${toBase64(
shimmer(700, 475)
)}`}
width={1920}
height={1080}
src={indeksRight?.thumbnailLink}
alt="image"
className="w-full h-[310px] lg:h-[215px] rounded-lg "
/>
<div className="absolute bottom-0 left-0 right-0 bg-black/15 backdrop-brightness-50 text-white p-4 rounded-b-lg">
<span className="text-white bg-[#bb3523] rounded-md w-full h-full font-semibold uppercase text-xs px-2 py-1">
{indeksRight?.categoryName}
</span>
2025-01-24 15:56:24 +00:00
<Link href={`/indeks/detail/${indeksRight?.slug}`}>
2025-04-07 16:37:19 +00:00
<h2 className="text-xl font-bold mt-2">
{indeksRight?.title}
</h2>
2025-01-24 15:56:24 +00:00
</Link>
<p className="text-xs flex flex-row items-center gap-1 mt-1 ml-2">
2025-04-07 16:37:19 +00:00
{formatDateToIndonesian(
new Date(indeksRight?.createdAt)
)}{" "}
{indeksRight?.timezone
? indeksRight?.timezone
: "WIB"}
|{" "}
{/* <svg
xmlns="http://www.w3.org/2000/svg"
width="1.2em"
height="1.2em"
viewBox="0 0 24 24"
>
2025-01-24 15:56:24 +00:00
<path
fill="currentColor"
d="M11.5 18c4 0 7.46-2.22 9.24-5.5C18.96 9.22 15.5 7 11.5 7s-7.46 2.22-9.24 5.5C4.04 15.78 7.5 18 11.5 18m0-12c4.56 0 8.5 2.65 10.36 6.5C20 16.35 16.06 19 11.5 19S3 16.35 1.14 12.5C3 8.65 6.94 6 11.5 6m0 2C14 8 16 10 16 12.5S14 17 11.5 17S7 15 7 12.5S9 8 11.5 8m0 1A3.5 3.5 0 0 0 8 12.5a3.5 3.5 0 0 0 3.5 3.5a3.5 3.5 0 0 0 3.5-3.5A3.5 3.5 0 0 0 11.5 9"
/>
</svg>{" "}
2025-04-07 16:37:19 +00:00
{indeksRight?.clickCount} */}
2025-01-24 15:56:24 +00:00
</p>
</div>
</div>
)
)}
</>
2024-12-13 14:33:59 +00:00
)}
</div>
2024-12-03 15:05:13 +00:00
</div>
2024-12-12 15:27:00 +00:00
2024-12-03 15:05:13 +00:00
{/* Bottom */}
2024-12-13 14:33:59 +00:00
<div className="px-4 lg:px-7 py-4">
2025-01-24 15:56:24 +00:00
{isLoading ? (
<div className="flex flex-col space-y-3 w-full gap-10">
2025-01-31 12:51:04 +00:00
<div className="flex flex-col lg:flex-row gap-5">
<Skeleton className="h-[300px] w-full lg:w-[500px] rounded-lg" />
2025-01-24 15:56:24 +00:00
<div className="space-y-2">
<Skeleton className="h-4 w-[250px]" />
<Skeleton className="h-4 w-[200px]" />
</div>
</div>
2025-01-31 12:51:04 +00:00
<div className="flex flex-col lg:flex-row gap-5">
<Skeleton className="h-[300px] w-full lg:w-[500px] rounded-lg" />
2025-01-24 15:56:24 +00:00
<div className="space-y-2">
<Skeleton className="h-4 w-[250px]" />
<Skeleton className="h-4 w-[200px]" />
</div>
</div>
2025-01-31 12:51:04 +00:00
<div className="flex flex-col lg:flex-row gap-5">
<Skeleton className="h-[300px] w-full lg:w-[500px] rounded-lg" />
2025-01-24 15:56:24 +00:00
<div className="space-y-2">
<Skeleton className="h-4 w-[250px]" />
<Skeleton className="h-4 w-[200px]" />
</div>
</div>
</div>
) : (
<div className="flex flex-col gap-4">
{indeksData?.map(
(indeksBottom: any, index: number) =>
index < 3 && (
2025-04-07 16:37:19 +00:00
<div
key={indeksBottom?.id}
className="flex flex-col md:flex-row items-start p-4 gap-4"
>
<Image
placeholder={`data:image/svg+xml;base64,${toBase64(
shimmer(700, 475)
)}`}
width={500}
height={250}
src={indeksBottom?.thumbnailLink}
alt=""
className="h-40 object-cover rounded-lg w-full lg:w-[550px] lg:h-[200px]"
/>
2025-01-24 15:56:24 +00:00
<div className="flex flex-col justify-between w-full">
<p className="text-sm">{indeksBottom?.date}</p>
2025-04-07 16:37:19 +00:00
<Link
href={`/indeks/detail/${indeksBottom?.slug}`}
className="text-2xl font-semibold text-gray-800 dark:text-white"
>
2025-01-24 15:56:24 +00:00
{indeksBottom?.title}
</Link>
2025-04-07 16:37:19 +00:00
<p className="text-sm text-gray-600 dark:text-white mt-2">
{htmlToString(indeksBottom?.description)}
</p>
2025-01-24 15:56:24 +00:00
</div>
2024-12-13 14:33:59 +00:00
</div>
2025-01-24 15:56:24 +00:00
)
)}
</div>
)}
2024-12-13 14:33:59 +00:00
</div>
2024-12-12 15:27:00 +00:00
</div>
2024-12-03 15:05:13 +00:00
);
};
2024-12-12 15:27:00 +00:00
export default Indeks;