import React, { useState } from 'react' import ArtworkCard from '../../gallery/ArtworkCard' function FavSkeleton() { return (
) } /** * TabFavourites * Shows artworks the user has favourited. */ export default function TabFavourites({ favourites, isOwner, username }) { const [items, setItems] = useState(favourites ?? []) const [nextCursor, setNextCursor] = useState(null) const [loadingMore, setLoadingMore] = useState(false) const loadMore = async () => { if (!nextCursor || loadingMore) return setLoadingMore(true) try { const res = await fetch( `/api/profile/${encodeURIComponent(username)}/favourites?cursor=${encodeURIComponent(nextCursor)}`, { headers: { Accept: 'application/json' } } ) if (res.ok) { const data = await res.json() setItems((prev) => [...prev, ...(data.data ?? data)]) setNextCursor(data.next_cursor ?? null) } } catch (_) {} setLoadingMore(false) } return (

{isOwner ? 'Your Favourites' : 'Favourites'}

{items.length === 0 ? (

No favourites yet

Artworks added to favourites will appear here.

) : ( <>
{items.map((art, i) => ( ))} {loadingMore && Array.from({ length: 4 }).map((_, i) => )}
{nextCursor && (
)} )}
) }