import { uploadImage, ImageUploadError } from '@cskn/sdk';
import { FilePicker, useToast } from '@cskn/ui';
function CoverUpload({ onUploaded }: { onUploaded: (url: string) => void }) {
const toast = useToast();
return (
<FilePicker
accept="image/*"
onSelect={async ([file]) => {
try {
const image = await uploadImage('/apps/blog/images', file);
onUploaded(image.url);
} catch (error) {
if (error instanceof ImageUploadError) {
toast.error(
error.reason === 'tooLarge' ? 'That image is too large.'
: error.reason === 'unreadable' ? 'That file is not an image we can read.'
: 'Upload failed. Try again.',
);
}
}
}}
/>
);
}