diff --git a/src/components/site/SiteHeader.tsx b/src/components/site/SiteHeader.tsx index 57cd0afd..3aebe6a9 100644 --- a/src/components/site/SiteHeader.tsx +++ b/src/components/site/SiteHeader.tsx @@ -76,9 +76,10 @@ export const SiteHeader: React.FC<{
{site?.banners?.[0]?.mime_type.split("/")[0] === "image" && ( banner )} {site?.banners?.[0]?.mime_type.split("/")[0] === "video" && ( diff --git a/src/components/ui/Avatar.tsx b/src/components/ui/Avatar.tsx index 10a009bc..b2efd1d3 100644 --- a/src/components/ui/Avatar.tsx +++ b/src/components/ui/Avatar.tsx @@ -63,7 +63,7 @@ export const Avatar: React.FC< }} > void) => { const reader = new FileReader() @@ -16,12 +18,23 @@ export const ImageUploader = forwardRef(function ImageUploader( image, uploadStart, uploadEnd, + withMimeType, + hasClose, ...inputProps }: { className?: string image?: string uploadStart?: () => void - uploadEnd?: (key: string) => void + uploadEnd?: ( + key: + | string + | { + address?: string + mime_type?: string + }, + ) => void + withMimeType?: boolean + hasClose?: boolean } & React.ComponentPropsWithRef<"input">, ref: React.ForwardedRef, ) { @@ -38,32 +51,94 @@ export const ImageUploader = forwardRef(function ImageUploader( setLoading(true) uploadStart?.() const key = (await uploadFile(event.target.files[0])).key - uploadEnd?.(key) + uploadEnd?.( + withMimeType + ? { + address: key, + mime_type: event.target.files[0].type, + } + : key, + ) setLoading(false) } else if (event.target.value) { setImageUrl(event.target.value) } } + + const clear = () => { + setImageUrl(undefined) + uploadEnd?.(withMimeType ? {} : "") + } + useEffect(() => { if (!imageUrl) { - setImageUrl((inputProps.value as string) || "") + setImageUrl( + ((withMimeType + ? (inputProps.value as any)?.address + : inputProps.value) as string) || "", + ) } }, [inputProps.value]) return (
- - {imageUrl && } + + {imageUrl && !withMimeType && ( + banner + )} + {imageUrl && + withMimeType && + (inputProps.value as any)?.mime_type.split("/")[0] === "image" && ( + banner + )} + {imageUrl && + withMimeType && + (inputProps.value as any)?.mime_type.split("/")[0] === "video" && ( +