Spaces:
Build error
Build error
File size: 1,243 Bytes
7df213d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import React, { useCallback } from 'react';
import { useDropzone } from 'react-dropzone';
const FileDropZone = ({ onFileDrop }) => {
const onDrop = useCallback(acceptedFiles => {
acceptedFiles.forEach(file => {
const reader = new FileReader();
reader.onload = () => {
const fileContent = reader.result;
onFileDrop({
content: fileContent,
type: file.type || 'text/plain', // Fallback for files without type
name: file.name
});
};
reader.readAsText(file);
});
}, [onFileDrop]);
const { getRootProps, getInputProps, isDragActive } = useDropzone({
onDrop,
accept: {
'text/plain': ['.txt'],
'application/json': ['.json'],
'text/yaml': ['.yml', '.yaml'],
'text/x-yaml': ['.yml', '.yaml']
},
multiple: false
});
return (
<div {...getRootProps()} className="dropzone">
<input {...getInputProps()} />
{isDragActive ? (
<p>Drop the file here...</p>
) : (
<div>
<p>Drag & drop a file here, or click to select</p>
<p className="file-types">Accepted files: .txt, .json, .yml, .yaml</p>
</div>
)}
</div>
);
};
export default FileDropZone; |