import { useState } from "react"; import { useDropzone } from "react-dropzone"; import { uploadDoc } from "../lib/fetchers"; const textFormats = [ ".doc", ".docx", ".md", ".txt", "text/*", "application/vnd.oasis.opendocument.text", ".odt", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ".rtf" ] function DocReceiver({ handleReceiveText }: { handleReceiveText: (content: string) => void, }) { const [state, setState] = useState(""); function onDrop(files: File[]) { uploadDoc(files[0], { error: () => setState("Error"), progress: (p) => setState(p < 100 ? `Uploading ${p}%...` : "Processing..."), complete: (m: string) => { setState(""); handleReceiveText(m); } }) } const {getRootProps, getInputProps, isDragActive} = useDropzone({ onDrop, multiple: false, accept: textFormats, }); return
{state ? state : "Drag file or click to add text file/document"}
; } export default DocReceiver;