import { useRef, useState } from "react"; import { Images, Upload } from "lucide-react"; import Image from "next/image"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { Page, Project } from "@/types"; import Loading from "@/components/loading"; import { RiCheckboxCircleFill } from "react-icons/ri"; import { useUser } from "@/hooks/useUser"; import { LoginModal } from "@/components/login-modal"; import { DeployButtonContent } from "../deploy-button/content"; export const Uploader = ({ pages, onLoading, isLoading, onFiles, onSelectFile, selectedFiles, files, project, }: { pages: Page[]; onLoading: (isLoading: boolean) => void; isLoading: boolean; files: string[]; onFiles: React.Dispatch>; onSelectFile: (file: string) => void; selectedFiles: string[]; project?: Project | null; }) => { const { user } = useUser(); const [open, setOpen] = useState(false); const fileInputRef = useRef(null); const uploadFiles = async (files: FileList | null) => { if (!files) return; if (!project) return; onLoading(true); const images = Array.from(files).filter((file) => { return file.type.startsWith("image/"); }); const data = new FormData(); images.forEach((image) => { data.append("images", image); }); const response = await fetch( `/api/me/projects/${project.space_id}/images`, { method: "POST", body: data, } ); if (response.ok) { const data = await response.json(); onFiles((prev) => [...prev, ...data.uploadedFiles]); } onLoading(false); }; // TODO FIRST PUBLISH YOUR PROJECT TO UPLOAD IMAGES. return user?.id ? (
{project?.space_id ? ( <>
🎨
🖼️
💻

Add Custom Images

Upload images to your project and use them with DeepSite!

Uploaded Images

{files.map((file) => (
onSelectFile(file)} > uploaded image {selectedFiles.includes(file) && (
)}
))}

Or import images from your computer

uploadFiles(e.target.files)} />
) : ( )}
) : ( <> setOpen(false)} pages={pages} title="Log In to add Custom Images" description="Log In through your Hugging Face account to publish your project and increase your monthly free limit." /> ); };