"use client"; import { Skeleton } from "@/components/ui/skeleton"; import { Link } from "@/i18n/routing"; import { getIndeksData } from "@/service/landing/landing"; import { formatDateToIndonesian } from "@/utils/globals"; import Image from "next/image"; import { usePathname } from "next/navigation"; import React, { useEffect, useState } from "react"; const Indeks: React.FC = () => { const pathname = usePathname(); const [isLoading, setIsLoading] = useState(true); const [indeksData, setIndeksData] = useState(); let count: number = 0; useEffect(() => { if (indeksData) { const intervalId = setInterval(() => { count = (count + 1) % indeksData.length; }, 5000); return () => clearInterval(intervalId); } }, [indeksData]); useEffect(() => { const timer = setTimeout(() => { setIsLoading(false); }, 3000); return () => clearTimeout(timer); }, []); useEffect(() => { initFetch(); }, []); const initFetch = async () => { const response = await getIndeksData(); console.log(response); setIndeksData(response?.data?.data?.content); }; const shimmer = (w: number, h: number) => ` `; const toBase64 = (str: string) => (typeof window === "undefined" ? Buffer.from(str).toString("base64") : window.btoa(str)); return (
{/* Hero Left */}
{isLoading ? (
) : (
{indeksData?.map( (indeks: any, index: number) => index == count && (
image
{indeks?.categoryName}

{indeks?.title}

{formatDateToIndonesian(new Date(indeks?.createdAt))} {indeks?.timezone ? indeks?.timezone : "WIB"} |{" "} {" "} {indeks?.clickCount}

) )}
)} {/* Hero Right */}
{isLoading ? ( <>
) : ( <> {indeksData?.map( (indeksRight: any, index: number) => (index == count + 1 || index == count + 2) && (
image
{indeksRight?.categoryName}

{indeksRight?.title}

{formatDateToIndonesian(new Date(indeksRight?.createdAt))} {indeksRight?.timezone ? indeksRight?.timezone : "WIB"}|{" "} {" "} {indeksRight?.clickCount}

) )} )}
{/* Bottom */}
{isLoading ? (
) : (
{indeksData?.map( (indeksBottom: any, index: number) => index < 3 && (

{indeksBottom?.date}

{indeksBottom?.title}

{indeksBottom?.description}

) )}
)}
); }; export default Indeks;