diff --git a/pages/collections.js b/pages/collections.js index 32aebbd..1334371 100644 --- a/pages/collections.js +++ b/pages/collections.js @@ -40,33 +40,52 @@ export default function Collections() { } }, [user]); + // Debug logging + useEffect(() => { + console.log('🔍 Debug - Current user:', user); + console.log('🔍 Debug - Collections:', collections.map(c => ({ + name: c.name, + userRole: c.userRole, + creator: c.creator + }))); + }, [user, collections]); + const fetchCollections = async () => { try { const response = await fetch('/api/collections'); + if (response.ok) { const data = await response.json(); - // Fetch thumbnail cards for each collection + console.log('🔍 Debug - API response:', data.map(c => ({ + name: c.name, + userRole: c.userRole, + creator: c.creator + }))); + + // Fetch thumbnails for each collection const collectionsWithThumbnails = await Promise.all( data.map(async (collection) => { try { const identifier = collection.slug || collection.id; const thumbnailResponse = await fetch(`/api/collections/${identifier}/thumbnails`); - const thumbnails = thumbnailResponse.ok ? await thumbnailResponse.json() : []; - return { ...collection, thumbnails }; + if (thumbnailResponse.ok) { + const thumbnailData = await thumbnailResponse.json(); + return { ...collection, thumbnails: thumbnailData.thumbnails }; + } + return { ...collection, thumbnails: [] }; } catch (error) { - console.error(`Error fetching thumbnails for collection ${collection.slug || collection.id}:`, error); + console.error(`Error fetching thumbnails for collection ${collection.id}:`, error); return { ...collection, thumbnails: [] }; } }) ); + setCollections(collectionsWithThumbnails); } else { console.error('Failed to fetch collections'); - setCollections([]); // Empty array on error } } catch (error) { console.error('Error fetching collections:', error); - setCollections([]); // Empty array on error } finally { setLoading(false); }