"use client"; import React, { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import categoryApi from "@/shared/services/category"; import CategoryCard from "./category-card"; import { ErrorState } from "@/shared/components/error-state"; import { Button } from "@/shared/components/button/button"; export function CategorySection() { const [showAll, setShowAll] = useState(false); const { data: categories, isLoading, isFetching, isSuccess, isError, error, refetch } = useQuery({ queryKey: ["categories-list", showAll], queryFn: () => categoryApi .getCategories( { ...(showAll ? {} : { limit: 6 }), filter: ["is_active=true"], }, { skipAuth: true } ) .then((res) => res.items), staleTime: 5000, retry: 1, }); const showSkeleton = isLoading || (isFetching && !isSuccess); return (

Topik

{!showAll ? ( ) : ( )}

Telusuri ragam topik yang tersedia!

{(() => { if (showSkeleton) { return (
{[...Array(6)].map((_, i) => (
))}
); } if (isError) { return ; } if (isSuccess && (!categories || categories.length === 0)) { return (
Belum ada kategori untuk ditampilkan.
); } if (isSuccess && categories && categories.length > 0) { return (
{categories.map((cat) => ( ))}
); } return null; })()}
); }