From 4c16ebd1d70d00cc95e65eac96046dc702a7372e Mon Sep 17 00:00:00 2001 From: Damien Ostler Date: Sun, 26 May 2024 18:01:53 -0400 Subject: [PATCH] fix:tooltips and badges and titles on thumbnails --- app/api/galleries/[id]/images/count/route.ts | 22 ++++ app/gallery/page.tsx | 2 +- components/ui/gallery_thumbnail.tsx | 104 +++++++++++++++---- 3 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 app/api/galleries/[id]/images/count/route.ts diff --git a/app/api/galleries/[id]/images/count/route.ts b/app/api/galleries/[id]/images/count/route.ts new file mode 100644 index 0000000..346502d --- /dev/null +++ b/app/api/galleries/[id]/images/count/route.ts @@ -0,0 +1,22 @@ +import { NextResponse } from "next/server"; +import { createClient } from "@/utils/supabase/server"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } + ) { + const galleryId = params.id; + const supabase = createClient(); + + // List all files in the galleryId path + let { data: files, error } = await supabase.storage.from('galleries').list(galleryId); + + if (files==null || error) { + console.error('Error listing files:', error); + return NextResponse.error(); + } + + + // Return a JSON response with the array of URLs + return new Response(JSON.stringify(files.length), { headers: { 'content-type': 'application/json' } }); +} \ No newline at end of file diff --git a/app/gallery/page.tsx b/app/gallery/page.tsx index aa0aac1..465b056 100644 --- a/app/gallery/page.tsx +++ b/app/gallery/page.tsx @@ -66,7 +66,7 @@ function PageComponent() {
{galleries.map((gallery, index) => ( - + ))}
diff --git a/components/ui/gallery_thumbnail.tsx b/components/ui/gallery_thumbnail.tsx index 4220412..8901b50 100644 --- a/components/ui/gallery_thumbnail.tsx +++ b/components/ui/gallery_thumbnail.tsx @@ -3,43 +3,111 @@ import { useState, useEffect } from 'react'; interface GalleryThumbnailProps { id: string; columns: number; - onSelect: (id:string, columns:number) => void; + onSelect: (id: string, columns: number) => void; + title: string; + subscription: string; } -const GalleryThumbnail = ({ id, columns, onSelect }: GalleryThumbnailProps) => { +const GalleryThumbnail = ({ id, columns, onSelect, title, subscription }: GalleryThumbnailProps) => { const [galleryId, setGalleryId] = useState(id); const [thumbnailUrl, setThumbnailUrl] = useState(''); const [isLoading, setIsLoading] = useState(true); const [galleryCollumns, setColumns] = useState(columns); + const [imageCount, setImageCount] = useState(0); + const openGallery = () => { onSelect(galleryId, galleryCollumns); }; const getData = async () => { - setIsLoading(true); - const thumbnailResponse = await fetch('/api/galleries/'+galleryId+'/thumbnail'); - const thumbnailUrl = await thumbnailResponse.text(); - setThumbnailUrl(thumbnailUrl); - setIsLoading(false); - } + setIsLoading(true); + const thumbnailResponse = await fetch('/api/galleries/' + galleryId + '/thumbnail'); + const thumbnailUrl = await thumbnailResponse.text(); + const imagesCountResponse = await fetch('/api/galleries/' + galleryId + '/images/count'); + const imageCount = await imagesCountResponse.json() as number; + setImageCount(imageCount); + setThumbnailUrl(thumbnailUrl); + setIsLoading(false); + }; useEffect(() => { - getData(); + getData(); }, []); return ( -
+
- {!isLoading && } + {!isLoading && ( + <> + +
+
+
+
+

{title}

+
+
+
+
+
+
{imageCount} pictures in this gallery.
+
+ + {imageCount} + + + + +
+
{imageCount} pictures in this gallery.
+
+
+ {subscription === "Free" && ( +
+ Free +
+
This is free for everyone.
+
+
+ )} + {subscription === "Tier 1" && ( +
+ Tier 1 +
+
This requires a Tier 1 subscription.
+
+
+ )} + {subscription === "Tier 2" && ( +
+ Tier 2 +
+
This requires a Tier 2 subscription.
+
+
+ )} + {subscription === "Tier 3" && ( +
+ Tier 3 +
+
This requires a Tier 3 subscription.
+
+
+ )} +
+
+
+ + )}
); -} +}; export default GalleryThumbnail; \ No newline at end of file