2024-06-02 03:48:21 -04:00
|
|
|
"use client";
|
|
|
|
import { createClient } from "@/utils/supabase/client";
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import Search from "@/components/neroshitron/search";
|
|
|
|
import Gallery from "@/components/neroshitron/gallery";
|
|
|
|
import Masonry from "react-masonry-css";
|
|
|
|
import SearchInput from "@/components/neroshitron/search_input";
|
2024-06-02 04:42:34 -04:00
|
|
|
import GalleryThumbnail from "@/components/neroshitron/gallery_thumbnail";
|
2024-06-02 03:48:21 -04:00
|
|
|
|
|
|
|
function PageComponent() {
|
|
|
|
const [filePreviews, setFilePreviews] = useState<string[]>([]);
|
|
|
|
const supabase = createClient();
|
|
|
|
const user = supabase.auth.getUser();
|
2024-06-02 22:52:44 -04:00
|
|
|
const [gallery , setGallery] = useState<any>(null);
|
2024-06-03 02:00:05 -04:00
|
|
|
const [originalName, setOriginalGalleryName] = useState<string>('');
|
2024-06-02 22:52:44 -04:00
|
|
|
const [galleryName, setGalleryName] = useState<string>('');
|
|
|
|
const [nsfw, setNsfw] = useState<boolean>(false);
|
|
|
|
const [tags, setTags] = useState<string[]>([]);
|
|
|
|
const [tier, setTier] = useState<string>('Free');
|
2024-06-03 02:00:05 -04:00
|
|
|
const [thumbnail, setThumbnail] = useState<string>();
|
|
|
|
const [fileNames, setFileNames] = useState<string[]>([]);
|
|
|
|
const [selectedTags, setSelectedTags] = useState<string[]>([]);
|
2024-06-02 22:52:44 -04:00
|
|
|
|
2024-06-03 02:10:39 -04:00
|
|
|
const [images, setImages] = useState<string[]>([]);
|
2024-06-02 22:52:44 -04:00
|
|
|
const getData = async () => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const id = urlParams.get('id');
|
|
|
|
const galleryResponse = await fetch(`/api/galleries/admin/${id}`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const galleryData = await galleryResponse.json();
|
|
|
|
setGallery(galleryData.gallery);
|
2024-06-03 02:00:05 -04:00
|
|
|
|
|
|
|
const filesResponse = await fetch(`/api/galleries/${id}/images/names`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const filesData = await filesResponse.json();
|
|
|
|
setFileNames(filesData);
|
|
|
|
|
2024-06-02 22:52:44 -04:00
|
|
|
setNsfw(galleryData.gallery.nsfw);
|
|
|
|
setTags(galleryData.gallery.tags);
|
|
|
|
setTier(galleryData.gallery.tier);
|
|
|
|
setGalleryName(galleryData.gallery.name);
|
2024-06-03 02:00:05 -04:00
|
|
|
if(originalName === ''){
|
|
|
|
setOriginalGalleryName(galleryData.gallery.name);
|
|
|
|
}
|
2024-06-03 02:10:39 -04:00
|
|
|
const imagesResponse = await fetch('/api/galleries/' + galleryData.gallery.name+ '/images');
|
|
|
|
const imagesUrls = await imagesResponse.json() as string[];
|
|
|
|
setImages(imagesUrls);
|
2024-06-02 22:52:44 -04:00
|
|
|
}
|
|
|
|
useEffect(() => {
|
|
|
|
getData();
|
|
|
|
}, []);
|
2024-06-03 02:00:05 -04:00
|
|
|
useEffect(() => {
|
|
|
|
}, [gallery]);
|
2024-06-02 22:52:44 -04:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-06-02 23:37:41 -04:00
|
|
|
}, [gallery, ]);
|
|
|
|
useEffect(() => {
|
|
|
|
}, [ nsfw ]);
|
|
|
|
useEffect(() => {
|
|
|
|
}, [tags ]);
|
|
|
|
useEffect(() => {
|
|
|
|
}, [galleryName]);
|
|
|
|
useEffect(() => {
|
|
|
|
}, [ tier]);
|
|
|
|
|
|
|
|
const updateGallery = async () => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const id = urlParams.get('id');
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('id', gallery.id);
|
|
|
|
formData.append('name', galleryName);
|
2024-06-03 02:00:05 -04:00
|
|
|
formData.append('thumbnail', thumbnail ?? '');
|
|
|
|
formData.append('originalName', originalName);
|
|
|
|
formData.append('tags', JSON.stringify(selectedTags));
|
2024-06-02 23:37:41 -04:00
|
|
|
formData.append('nsfw', nsfw.toString());
|
|
|
|
formData.append('tier', tier);
|
2024-06-03 02:00:05 -04:00
|
|
|
const response = await fetch(`/api/galleries/admin/${originalName}`, {
|
2024-06-02 23:37:41 -04:00
|
|
|
method: 'PUT',
|
2024-06-03 02:00:05 -04:00
|
|
|
body: formData
|
2024-06-02 23:37:41 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
if (response.ok) {
|
2024-06-03 02:00:05 -04:00
|
|
|
console.log(response)
|
2024-06-02 23:37:41 -04:00
|
|
|
const data = await response.json();
|
|
|
|
} else {
|
|
|
|
console.log(response)
|
|
|
|
}
|
2024-06-03 02:00:05 -04:00
|
|
|
if(originalName != galleryName){
|
|
|
|
window.location.href=`/gallery/admin/view?id=${galleryName}`
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteGallery = async () => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const id = urlParams.get('id');
|
|
|
|
const response = await fetch(`/api/gallery/admin/${id}`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (response.ok) {
|
|
|
|
const data = await response.json();
|
|
|
|
window.location.href = "/gallery/admin";
|
|
|
|
} else {
|
|
|
|
console.log(response)
|
|
|
|
}
|
2024-06-02 23:37:41 -04:00
|
|
|
}
|
2024-06-02 03:48:21 -04:00
|
|
|
|
|
|
|
return (
|
2024-06-03 02:00:05 -04:00
|
|
|
<div className="w-full text-white flex justify-center items-center animate-in">
|
2024-06-02 22:52:44 -04:00
|
|
|
<div className="w-full lg:w-1/2 rounded-md p-12 mt-14 ">
|
|
|
|
<div className="w-full flex pb-60">
|
|
|
|
{gallery != null && (
|
|
|
|
<GalleryThumbnail
|
2024-06-02 23:37:41 -04:00
|
|
|
key={"galleryThumbnail"+galleryName+"-"+tags.join("")}
|
2024-06-03 02:00:05 -04:00
|
|
|
id={originalName}
|
2024-06-02 22:52:44 -04:00
|
|
|
columns={3}
|
|
|
|
onSelect={function (id: string, columns: number): void {}}
|
|
|
|
title={galleryName}
|
|
|
|
subscription={tier}
|
|
|
|
tags={tags}
|
2024-06-02 23:37:41 -04:00
|
|
|
showNsfw={false}
|
2024-06-02 22:52:44 -04:00
|
|
|
nsfw={nsfw}
|
|
|
|
></GalleryThumbnail>
|
|
|
|
)}
|
2024-06-02 04:42:34 -04:00
|
|
|
</div>
|
2024-06-02 22:52:44 -04:00
|
|
|
<div className="w-full flex opacity-90 backdrop-blur-lg bg-primary shadow-lg p-8 pb-0 rounded">
|
2024-06-02 03:48:21 -04:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
className="mb-8 mr-2 rounded-md bg-secondary p-2 w-1/2 text-white"
|
|
|
|
placeholder="Gallery Name"
|
2024-06-02 22:52:44 -04:00
|
|
|
value={galleryName}
|
|
|
|
onChange={(e) => setGalleryName(e.target.value)}
|
2024-06-02 03:48:21 -04:00
|
|
|
/>
|
2024-06-02 04:46:21 -04:00
|
|
|
<div className="w-1/6">
|
2024-06-02 22:52:44 -04:00
|
|
|
<button
|
2024-06-03 02:00:05 -04:00
|
|
|
onClick={() => deleteGallery()}
|
2024-06-02 22:52:44 -04:00
|
|
|
className="w-full bg-error hover:bg-error-light text-white rounded-md p-2"
|
|
|
|
>
|
2024-06-02 04:46:21 -04:00
|
|
|
Delete
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="w-1/6">
|
2024-06-02 22:52:44 -04:00
|
|
|
<button
|
|
|
|
onClick={() => (window.location.href = "/gallery/admin")}
|
|
|
|
className="w-full bg-error-dark hover:bg-error text-white rounded-md p-2 ml-2"
|
|
|
|
>
|
2024-06-02 04:25:36 -04:00
|
|
|
Back
|
2024-06-02 03:48:21 -04:00
|
|
|
</button>
|
|
|
|
</div>
|
2024-06-02 04:25:36 -04:00
|
|
|
<div className="w-1/4">
|
2024-06-02 23:37:41 -04:00
|
|
|
<button onClick={()=>{updateGallery()}} className="w-full bg-success hover:bg-success-light text-white rounded-md p-2 ml-4">
|
2024-06-02 07:43:33 -04:00
|
|
|
Save
|
2024-06-02 04:25:36 -04:00
|
|
|
</button>
|
2024-06-02 03:48:21 -04:00
|
|
|
</div>
|
2024-06-02 04:25:36 -04:00
|
|
|
</div>
|
2024-06-02 22:52:44 -04:00
|
|
|
<div className="w-full flex opacity-90 backdrop-blur-lg bg-primary shadow-lg p-8 pt-0 rounded">
|
2024-06-02 04:25:36 -04:00
|
|
|
<div className="w-1/2 mr-2">
|
2024-06-03 02:00:05 -04:00
|
|
|
{gallery &&(
|
2024-06-02 03:48:21 -04:00
|
|
|
<SearchInput
|
2024-06-03 02:00:05 -04:00
|
|
|
placeholderTags={[
|
|
|
|
{ value: "tags", label: "❗️ click here to add tags" },
|
|
|
|
]}
|
|
|
|
startingTags={gallery.tags}
|
2024-06-02 22:52:44 -04:00
|
|
|
nsfwButtonEnabled={true}
|
2024-06-02 03:48:21 -04:00
|
|
|
searchChanged={(search) => {}}
|
|
|
|
nsfwChanged={(nsfw) => {}}
|
2024-06-03 02:00:05 -04:00
|
|
|
tagsChanged={(tags) => { setSelectedTags(tags) }}
|
2024-06-02 03:48:21 -04:00
|
|
|
/>
|
2024-06-03 02:00:05 -04:00
|
|
|
)}
|
2024-06-02 03:48:21 -04:00
|
|
|
</div>
|
|
|
|
<div className="w-1/2">
|
2024-06-02 22:52:44 -04:00
|
|
|
{gallery != null && (<>
|
|
|
|
<select value={nsfw ? "NSFW" : "SFW"} className="mb-2 shadow-lg rounded-md bg-secondary p-2 w-full text-white" onChange={e=>{
|
2024-06-03 02:00:05 -04:00
|
|
|
setNsfw(e.target.value == "NSFW");
|
2024-06-02 22:52:44 -04:00
|
|
|
}}>
|
2024-06-03 02:00:05 -04:00
|
|
|
<option value="" disabled >Set NSFW</option>
|
2024-06-02 22:52:44 -04:00
|
|
|
<option value="NSFW" selected={nsfw}>NSFW</option>
|
2024-06-03 02:00:05 -04:00
|
|
|
<option value="SFW" selected={!nsfw}>SFW</option>
|
2024-06-02 04:37:59 -04:00
|
|
|
</select>
|
2024-06-03 02:00:05 -04:00
|
|
|
<select onChange={e=>{
|
|
|
|
setTier(e.target.value);
|
|
|
|
|
|
|
|
}} className="mb-2 shadow-lg mr-2 rounded-md bg-secondary p-2 w-full text-white">
|
|
|
|
<option value="" disabled >Select New Tier</option>
|
2024-06-02 22:52:44 -04:00
|
|
|
<option value="Free" selected={tier === "Free"}>Free</option>
|
|
|
|
<option value="Tier 1" selected={tier === "Tier 1"}>Tier 1</option>
|
|
|
|
<option value="Tier 2" selected={tier === "Tier 2"}>Tier 2</option>
|
|
|
|
<option value="Tier 3" selected={tier === "Tier 3"}>Tier 3</option>
|
2024-06-02 04:37:59 -04:00
|
|
|
</select>
|
2024-06-03 02:00:05 -04:00
|
|
|
<select onChange={e=>{setThumbnail(e.target.value)}} className="mb-2 shadow-lg mr-2 rounded-md bg-secondary p-2 w-full text-white">
|
2024-06-02 04:37:59 -04:00
|
|
|
<option value="" disabled selected>Select New Thumbnail</option>
|
2024-06-03 02:00:05 -04:00
|
|
|
{fileNames.map((name, index) => (
|
|
|
|
<option selected={name==gallery.thumbnail_file} key={index} value={name}>{name}</option>
|
|
|
|
))}
|
2024-06-02 04:35:15 -04:00
|
|
|
</select>
|
2024-06-02 22:52:44 -04:00
|
|
|
</>
|
|
|
|
)}
|
2024-06-02 03:48:21 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-03 02:10:39 -04:00
|
|
|
<div className="w-full flex opacity-90 backdrop-blur-lg bg-primary shadow-lg p-8 pt-0 rounded">
|
|
|
|
|
|
|
|
<Masonry
|
|
|
|
breakpointCols={3}
|
|
|
|
className="my-masonry-grid pl-6 "
|
|
|
|
>
|
|
|
|
{images.map((image, index) => (
|
|
|
|
<img
|
|
|
|
key={index}
|
|
|
|
src={image}
|
|
|
|
className={`animate-in animate-once animate-duration-1000 animate-ease-out animate-reverse hover:scale-105 p-2 cursor-pointer my-2 transition-all opacity-100 duration-500 ease-in-out transform`}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Masonry>
|
|
|
|
</div>
|
2024-06-02 03:48:21 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
export default PageComponent;
|