// // SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // "use client" import type React from "react" import { useState } from "react" import { Upload, AlertCircle, FileText } from "lucide-react" import { useDocuments } from "@/contexts/document-context" export function UploadDocuments() { const { addDocuments } = useDocuments() const [isDragging, setIsDragging] = useState(false) const [error, setError] = useState(null) const validateFiles = (files: File[]): File[] => { setError(null) const validFiles = Array.from(files).filter((file) => { const isValidType = file.name.endsWith(".md") || file.name.endsWith(".csv") || file.name.endsWith(".txt") || file.name.endsWith(".json") if (!isValidType) { setError("Only markdown (.md), CSV (.csv), text (.txt), and JSON (.json) files are supported.") return false } return true }) return validFiles } const handleDragOver = (e: React.DragEvent) => { e.preventDefault() setIsDragging(true) } const handleDragLeave = () => { setIsDragging(false) } const handleDrop = (e: React.DragEvent) => { e.preventDefault() setIsDragging(false) const files = Array.from(e.dataTransfer.files) const validFiles = validateFiles(files) if (validFiles.length > 0) { addDocuments(validFiles) } } const handleFileSelect = (e: React.ChangeEvent) => { if (e.target.files) { const files = Array.from(e.target.files) const validFiles = validateFiles(files) if (validFiles.length > 0) { addDocuments(validFiles) } // Reset the input to allow uploading the same file again e.target.value = "" } } return (
{error && (

{error}

)}
document.getElementById("file-upload")?.click()} >

Drag & Drop Files

or

.md, .csv, .txt, .json supported
) }