import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import GlobalContext from "@/contexts/GlobalContext"; import { FileInfo } from "@/types"; import { Images, Send, X } from "lucide-react"; import { useContext, useRef, useState } from "react"; const InputArea = () => { const [inputValue, setInputValue] = useState(""); const { handleSend, selectedFile, setSelectedFile, setFile } = useContext(GlobalContext); const [loading, setLoading] = useState(false); const ref = useRef(null); const fileInputRef = useRef(null) const handleFileChange = (event: React.ChangeEvent) => { const file = event.target.files?.[0] if (file) { setSelectedFile({ name: file.name, type: file.type, size: file.size }) setFile(file) } } const handleSendController = async () => { setLoading(true); setInputValue(""); await handleSend(inputValue); setLoading(false); // focus on input setTimeout(() => { ref.current?.focus(); }, 0); }; const handleClosePopup = () => { setSelectedFile(null) if (fileInputRef.current) { fileInputRef.current.value = '' } } return ( <>
{selectedFile && }
setInputValue(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleSendController()} placeholder="Type a message..." className="flex-1 pl-10 rounded-3xl" disabled={loading} ref={ref} />
); }; const FileInfoPopup = ({ file, onClose }: { file: FileInfo, onClose: () => void }) => { return (

{file.name}

Type: {file.type}

Size: {(file.size / 1024).toFixed(2)} KB

) } export default InputArea;