MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / FileDropzone

Function FileDropzone

app/components/FileSelector/FileDropzone.tsx:5–52  ·  view source on GitHub ↗
({ children })

Source from the content-addressed store, hash-verified

3import { DocumentDownloadIcon } from "@heroicons/react/outline";
4
5export const FileDropzone: FunctionComponent = ({ children }) => {
6 const onDrop = useCallback((acceptedFiles) => {
7 acceptedFiles.forEach((file: Blob) => {
8 const reader = new FileReader();
9 reader.onabort = () => console.log("file reading was aborted");
10 reader.onerror = () => console.log("file reading has failed");
11 reader.onload = () => {
12 if (typeof reader.result === "string") {
13 let json = JSON.parse(reader.result);
14 // dataSourceDispatch(setJSONAction("Needs title", json));
15 } else {
16 // dataSourceDispatch(setErrorAction("Can't read file"));
17 }
18 };
19 reader.readAsText(file);
20 });
21 }, []);
22
23 const { getRootProps, isDragActive } = useDropzone({
24 onDrop,
25 multiple: false,
26 maxFiles: 1,
27 accept: "application/json, text/*",
28 noDragEventsBubbling: true,
29 });
30
31 return (
32 <div
33 {...getRootProps()}
34 className={"absolute w-screen h-screen m-0 p-0 left-0 top-0"}
35 >
36 <div
37 className={`${
38 isDragActive ? "" : "hidden"
39 } absolute w-screen h-screen bg-black bg-opacity-50 flex justify-center items-center`}
40 >
41 <div className={"text-center"}>
42 {/*<input {...getInputProps()} />*/}
43 <DocumentDownloadIcon className={"w-72 h-72 text-white"} />
44 <p className={"text-white text-2xl"}>
45 Drag 'n' drop some files here, or click to select files
46 </p>
47 </div>
48 </div>
49 <div>{children}</div>
50 </div>
51 );
52};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected