96 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-05-26 02:14:59 -04:00
"use client";
import { createClient } from "@/utils/supabase/client";
import { redirect } from "next/navigation";
import GalleryThumbnail from "@/components/ui/gallery_thumbnail";
import React, { useState, useEffect } from 'react';
import { User } from "@supabase/supabase-js";
import Gallery from "@/components/ui/gallery";
function PageComponent() {
const supabase = createClient();
2024-05-26 03:46:00 -04:00
const [randomIds, setRandomIds] = useState<string[]>([]); // replace any with your gallery type
2024-05-26 02:14:59 -04:00
const [isOpen, setIsOpen] = useState<boolean>(false);
const [galleries, setGalleries] = useState<any[]>([]); // replace any with your gallery type
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState<boolean>(true);
2024-05-26 13:08:59 -04:00
const [selectedGallery, setSelectedGallery] = useState<string | null>(null);
2024-05-26 16:58:48 -04:00
const [galleryColumns, setColumns] = useState<number>(0);
2024-05-26 03:46:00 -04:00
const generateRandomString = function (length:number) {
let result = '';
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
2024-05-26 02:14:59 -04:00
2024-05-26 16:58:48 -04:00
const selectGallery = (gallery:string, columns:number) => {
2024-05-26 03:46:00 -04:00
setRandomIds([generateRandomString(3), generateRandomString(3), generateRandomString(3), generateRandomString(3)]);
2024-05-26 02:14:59 -04:00
setSelectedGallery(gallery);
2024-05-26 16:58:48 -04:00
setColumns(columns);
2024-05-26 02:14:59 -04:00
setIsOpen(true);
};
2024-05-26 14:36:20 -04:00
const closeGallery = () => {
setSelectedGallery(null);
2024-05-26 16:58:48 -04:00
setColumns(0);
2024-05-26 14:36:20 -04:00
setIsOpen(false);
}
2024-05-26 02:14:59 -04:00
const getData = async () => {
const galleriesResponse = await fetch('/api/galleries');
const galleriesData = await galleriesResponse.json();
let { data: { user } } = await supabase.auth.getUser();
setGalleries(galleriesData);
setUser(user);
setLoading(false);
}
useEffect(() => {
getData();
2024-05-26 03:46:00 -04:00
}, []);
2024-05-26 02:14:59 -04:00
return ( ( user ? (
<div className="w-full h-full flex justify-center">
<div className="flex-1 w-full h-full flex flex-col gap-20">
2024-05-26 03:46:00 -04:00
<>
2024-05-26 16:36:45 -04:00
<div className="absolute w-full h-full overflow-hidden z-0 animate-flip-up animate-ease-out">
2024-05-26 02:14:59 -04:00
<img src="gallery_girl.png" className="float-right object-cover h-screen w-3/6" alt="Background" />
</div>
2024-05-26 16:36:45 -04:00
<div className="absolute items-center w-3/5 h-full ml-10 z-0 overflow-hidden nimate-fade animate-ease-out">
2024-05-26 14:36:20 -04:00
<div className="grid grid-cols-3 gap-y-36 gap-x-10 h-full overflow-y-auto no-scrollbar pt-36">
2024-05-26 02:14:59 -04:00
{galleries.map((gallery, index) => (
2024-05-26 16:58:48 -04:00
<GalleryThumbnail key={index} id={gallery.id} columns={gallery.columns} onSelect={selectGallery}></GalleryThumbnail>
2024-05-26 02:14:59 -04:00
))}
</div>
</div>
2024-05-26 03:46:00 -04:00
</>
2024-05-26 02:14:59 -04:00
</div>
{(isOpen ? (
<>
2024-05-26 16:36:45 -04:00
<div className={`fixed inset-0 transition-opacity z-30 ${isOpen ? 'animate-in' : 'fade-out'}`} aria-hidden="true">
<div className="absolute inset-0 bg-neroshi-blue-900 opacity-70 z-30" onClick={()=>setIsOpen(false)} >
2024-05-26 02:14:59 -04:00
</div>
2024-05-26 16:36:45 -04:00
<div className="absolute inset-0 overflow-y-auto overflow-x-hidden no-scrollbar pt-2 w-full p-20 z-30">
2024-05-26 16:58:48 -04:00
<Gallery id={selectedGallery as string} columns={galleryColumns} closeMenu={() => closeGallery()}></Gallery>
2024-05-26 02:14:59 -04:00
</div>
</div>
</>
): null)}
</div>
) : (
<h1>loading</h1>
)));
}
export default PageComponent;