Spaces:
Build error
Build error
Download frontend/src/components/FileDropZone.js from sp103107/agent-system: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/sp103107/agent-system/resolve/main/frontend/src/components/FileDropZone.js
- Command line
-
hf download hf://spaces/sp103107/agent-system/frontend/src/components/FileDropZone.js
-
curl -L -o FileDropZone.js https://huggingface.co/spaces/sp103107/agent-system/resolve/main/frontend/src/components/FileDropZone.js
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; |