import { PhotoIcon } from "@heroicons/react/24/outline"; import { TRANSFORMS } from "@hey/data/constants"; import imageKit from "@hey/helpers/imageKit"; import sanitizeDStorageUrl from "@hey/helpers/sanitizeDStorageUrl"; import type { ApolloClientError } from "@hey/types/errors"; import type { ChangeEvent, Ref } from "react"; import { useCallback, useState } from "react"; import { Image, Spinner } from "@/components/Shared/UI"; import cn from "@/helpers/cn"; import errorToast from "@/helpers/errorToast"; import { uploadFileToIPFS } from "@/helpers/uploadToIPFS"; interface CoverImageProps { cover: string; imageRef: Ref; isNew: boolean; setCover: (previewUri: string, url: string, mimeType: string) => void; } const CoverImage = ({ cover, imageRef, isNew = false, setCover }: CoverImageProps) => { const [isSubmitting, setIsSubmitting] = useState(false); const onError = useCallback((error: ApolloClientError) => { setIsSubmitting(false); errorToast(error); }, []); const onChange = async (event: ChangeEvent) => { if (event.target.files?.length) { try { setIsSubmitting(true); const file = event.target.files[0]; const attachment = await uploadFileToIPFS(file); setCover( URL.createObjectURL(file), attachment.uri, file.type || "image/jpeg" ); } catch (error) { onError(error); } } }; return (
{isNew && ( )}
); }; export default CoverImage;