vision-agent / lib /hooks /useImageUpload.ts
MingruiZhang's picture
Larger layout / allow logout user to upload / move image to chat box (#13)
38448fc unverified
import { DropzoneOptions, useDropzone } from 'react-dropzone';
// import { toast } from 'react-hot-toast';
const useImageUpload = (
options?: Partial<DropzoneOptions>,
onDrop?: (files: File[]) => void,
) => {
const { getRootProps, getInputProps, isDragActive } = useDropzone({
accept: {
'image/*': ['.jpeg', '.png'],
},
multiple: false,
onDrop: onDrop
? onDrop
: acceptedFiles => {
// if (acceptedFiles.length > 10) {
// toast('You can only upload 10 images max.', {
// icon: '⚠️',
// });
// }
acceptedFiles.forEach(file => {
try {
const reader = new FileReader();
reader.onloadend = () => {};
reader.readAsDataURL(file);
} catch (err) {
console.error(err);
}
});
},
...options,
});
return { getRootProps, getInputProps, isDragActive };
};
export default useImageUpload;