"use client"; import { useCallback, useState } from "react"; import { useDropzone } from "react-dropzone"; import axios from "axios"; import { Message } from "@/lib/types"; export default function UploadPage() { const [message, setMessage] = useState(null); const onDrop = useCallback(async (acceptedFiles: File[]) => { const file = acceptedFiles[0]; const formData = new FormData(); formData.append("file", file); try { const response = await axios.post( "http://localhost:8000/upload", formData ); setMessage({ type: "success", text: "File uploaded successfully: " + JSON.stringify(response.data), }); } catch (error: any) { setMessage({ type: "error", text: "Failed to upload file: " + error.toString(), }); } }, []); const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop, }); return (
{isDragActive ? (

Drop the files here...

) : (

Drag 'n' drop some files here, or click to select files

)}
{message && (

{message.text}

)}
); }