import { UploadCloudIcon } from "lucide-react"; import { useRef, useState } from "react"; import toast from "react-hot-toast"; import type { AssetDescriptor } from "../../types"; export default function Uploader({ onUploaded, uploadAsset, }: { onUploaded: (payload: AssetDescriptor) => void; uploadAsset: (file: File) => Promise; }) { const [stagedImages, setStagedImages] = useState([]); const imagePickerRef = useRef(null); // TODO: move this out of the cms folder const upload = async (image: File) => { try { const asset = await uploadAsset(image); onUploaded(asset); toast.success("Asset uploaded"); } catch (error) { console.error(error); toast.error("Failed to upload asset"); } }; return (
{stagedImages.map((_, i) => (
Staged
))}
{ if (e.target.files) { setStagedImages((images) => [...images, ...e.target.files!]); } }} />
); }