'use client'; import Link from 'next/link'; import { useState, useEffect } from 'react'; import { fetchGenres } from '@/lib/api'; export default function GenreList() { const [genres, setGenres] = useState([]); const [isLoading, setIsLoading] = useState(true); const [showAll, setShowAll] = useState(false); useEffect(() => { async function loadGenres() { try { const genreData = await fetchGenres(); setGenres(genreData || []); } catch (error) { console.error("Error fetching genres:", error); } finally { setIsLoading(false); } } loadGenres(); }, []); // Predefined popular genres if API doesn't return them const defaultGenres = [ "Action", "Adventure", "Comedy", "Drama", "Fantasy", "Horror", "Mystery", "Romance", "Sci-Fi", "Slice of Life", "Supernatural", "Thriller", "Isekai", "Mecha", "Sports" ]; // Use fetched genres or fallback to default genres const displayGenres = genres.length > 0 ? genres : defaultGenres; // Show only first 12 genres if not showing all const visibleGenres = showAll ? displayGenres : displayGenres.slice(0, 12); if (isLoading) { return (

Genres

{[...Array(12)].map((_, i) => (
))}
); } return (

Genres

{visibleGenres.map((genre) => ( {genre} ))}
{displayGenres.length > 12 && (
)}
); }