From 164aec1c514f83d7bdcc3c6df276f4a2a30c9452 Mon Sep 17 00:00:00 2001 From: Damien Ostler Date: Sat, 8 Jun 2024 19:11:32 -0400 Subject: [PATCH] fix: hooked up tiers to galleries page --- components/neroshitron/galleries.tsx | 44 ++++++++++++++------ components/neroshitron/gallery_thumbnail.tsx | 20 +++------ 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/components/neroshitron/galleries.tsx b/components/neroshitron/galleries.tsx index 93f21f5..fb3528c 100644 --- a/components/neroshitron/galleries.tsx +++ b/components/neroshitron/galleries.tsx @@ -17,6 +17,7 @@ const Galleries = ({ nsfw, tags, search, gallerySelected }: TagProps) => { const [searchState, setSearchState] = useState(search); const [selectedGallery, setSelectedGallery] = useState(null); + const [tiers, setTiers] = useState([]); const selectGallery = (gallery: string) => { setSelectedGallery(gallery); @@ -25,6 +26,17 @@ const Galleries = ({ nsfw, tags, search, gallerySelected }: TagProps) => { const getData = async () => { + try { + const response = await fetch('/api/tiers'); + if (response.ok) { + const data = await response.json(); + setTiers(data); + } else { + console.error('Failed to fetch users'); + } + } catch (error) { + console.error('Error fetching users:', error); + } const galleriesResponse = await fetch(`/api/galleries?search=` + searchState + '&nsfw=' + nsfwState, { method: 'POST', headers: { @@ -43,19 +55,25 @@ const Galleries = ({ nsfw, tags, search, gallerySelected }: TagProps) => { return (
- {galleries && galleries.map((gallery: any, index) => ( - - ))} + {galleries && galleries.map((gallery: any, index) => { + const tier = tiers.find((tier) => tier.name == gallery.tier); + const subscriptionColor = tier ? tier.color : null; + + return ( + + ); + })}
); }; diff --git a/components/neroshitron/gallery_thumbnail.tsx b/components/neroshitron/gallery_thumbnail.tsx index 1ecb598..c306d69 100644 --- a/components/neroshitron/gallery_thumbnail.tsx +++ b/components/neroshitron/gallery_thumbnail.tsx @@ -6,12 +6,13 @@ interface GalleryThumbnailProps { onSelect: (id: string, columns: number) => void; title: string; subscription: string; + subscriptionColor: string; tags: string[]; showNsfw: boolean; nsfw: boolean; } -const GalleryThumbnail = ({ id, columns, onSelect, title, showNsfw, nsfw, subscription, tags }: GalleryThumbnailProps) => { +const GalleryThumbnail = ({ id, columns, onSelect, title, showNsfw, nsfw, subscription, subscriptionColor, tags }: GalleryThumbnailProps) => { const [galleryId, setGalleryId] = useState(id); const [thumbnailUrl, setThumbnailUrl] = useState(''); const [isLoading, setIsLoading] = useState(true); @@ -21,6 +22,7 @@ const GalleryThumbnail = ({ id, columns, onSelect, title, showNsfw, nsfw, subscr const [showNsfwState, setShowNsfw] = useState(showNsfw); const [subscriptionState, setSubscription] = useState(subscription); const [tagsState, setTags] = useState(tags); + console.log(subscriptionColor) const openGallery = () => { onSelect(galleryId, galleryCollumns); }; @@ -42,7 +44,7 @@ const GalleryThumbnail = ({ id, columns, onSelect, title, showNsfw, nsfw, subscr return (
-
+
{!isLoading ? ( <> NSFW )} - {subscriptionState === "Free" && ( - Free - )} - {subscriptionState === "Tier 1" && ( - Tier 1 - )} - {subscriptionState === "Tier 2" && ( - Tier 2 - )} - {subscriptionState === "Tier 3" && ( - Tier 3 - )} + Free +
{/*