import { Plus, Send, Trash } from "lucide-react" import React from "react" import { sendMessage } from "~/lib/api/client/channel" import { uploadFiles } from "~/lib/api/client/file" import TextBox from "./custom-ui/text-box" import { Button } from "./ui/button" export interface MessageBoxProps { channelId: string } export default function MessageBox( { channelId }: MessageBoxProps ) { const [text, setText] = React.useState("") const [attachments, setAttachments] = React.useState([]) const fileInputRef = React.useRef(null) const onSendMessage = async () => { const content = text.trim() if (!content && !attachments.length) return const uploadedAttachments = await uploadFiles(attachments) await sendMessage(channelId, text, uploadedAttachments) setText("") setAttachments([]) } const addAttachment = async () => { if (!fileInputRef.current) return fileInputRef.current.click() } const onFileChange = (e: React.ChangeEvent) => { const files = Array.from(e.target.files || []) const newAttachments = [...attachments, ...files] setAttachments(newAttachments.slice(0, 10)) if (!fileInputRef.current) return fileInputRef.current.value = "" } React.useEffect(() => { setText("") setAttachments([]) }, [channelId]) return (
0 ? "pt-2" : "hidden"}`}>
{ attachments.map((file, i) => (
{file.name}
)) }
) }