"use client"; import { useSearchParams } from "next/navigation"; import Link from "next/link"; import useSWR from "swr"; import { Icon } from "@iconify/react"; import Skeleton from "./skeleton"; import FilterSelect from "./filter-select"; import SortSelect from "./sort-select"; import Carousel from "../carousel"; import LikeButton from "../like-button"; import DeleteMiiButton from "../delete-mii"; import Pagination from "./pagination"; interface Props { isLoggedIn: boolean; // Profiles userId?: number; } interface ApiResponse { total: number; filtered: number; lastPage: number; miis: { id: number; user?: { id: number; username: string; }; name: string; imageCount: number; tags: string[]; createdAt: string; likes: number; isLiked: boolean; }[]; } const fetcher = (url: string) => fetch(url).then((res) => res.json()); export default function MiiList({ isLoggedIn, userId }: Props) { const searchParams = useSearchParams(); const { data, error } = useSWR(`/api/mii/list?${searchParams.toString()}`, fetcher); return (

{data ? ( data.total == data.filtered ? ( <> {data.total} Miis ) : ( <> {data.filtered} of {data.total} Miis ) ) : ( <> 0 Miis )}

{data ? ( data.miis.length > 0 ? (
{data.miis.map((mii) => (
`/mii/${mii.id}/image${index}.webp`), ]} />
{mii.name}
{mii.tags.map((tag) => ( {tag} ))}
{!userId ? ( @{mii.user?.username} ) : (
)}
))}
) : (

No results found.

) ) : error ? (

Error: {error}

) : ( // Show skeleton when data is loading
{Array.from({ length: 24 }).map((_, i) => ( ))}
)} {data && }
); }