agent-system / frontend /src /components /FileDropZone.js
s-diffusion's picture
Initial commit
7df213d
Raw History Blame Contribute Delete
1.24 kB
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;