import { SendIcon, StopCircleIcon, Paperclip } from "lucide-react"; import type React from "react"; import { useEffect, useRef } from "react"; import { useSettings } from "@/hooks/useSettings"; import { homeChatInputValueAtom } from "@/atoms/chatAtoms"; // Use a different atom for home input import { useAtom } from "jotai"; import { useStreamChat } from "@/hooks/useStreamChat"; import { useAttachments } from "@/hooks/useAttachments"; import { AttachmentsList } from "./AttachmentsList"; import { DragDropOverlay } from "./DragDropOverlay"; import { usePostHog } from "posthog-js/react"; import { HomeSubmitOptions } from "@/pages/home"; import { ChatInputControls } from "../ChatInputControls"; export function HomeChatInput({ onSubmit, }: { onSubmit: (options?: HomeSubmitOptions) => void; }) { const posthog = usePostHog(); const [inputValue, setInputValue] = useAtom(homeChatInputValueAtom); const textareaRef = useRef(null); const { settings } = useSettings(); const { isStreaming } = useStreamChat({ hasChatId: false, }); // eslint-disable-line @typescript-eslint/no-unused-vars // Use the attachments hook const { attachments, fileInputRef, isDraggingOver, handleAttachmentClick, handleFileChange, removeAttachment, handleDragOver, handleDragLeave, handleDrop, clearAttachments, } = useAttachments(); const adjustHeight = () => { const textarea = textareaRef.current; if (textarea) { textarea.style.height = "0px"; const scrollHeight = textarea.scrollHeight; textarea.style.height = `${scrollHeight + 4}px`; } }; useEffect(() => { adjustHeight(); }, [inputValue]); const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleCustomSubmit(); } }; // Custom submit function that wraps the provided onSubmit const handleCustomSubmit = () => { if ((!inputValue.trim() && attachments.length === 0) || isStreaming) { return; } // Call the parent's onSubmit handler with attachments onSubmit({ attachments }); // Clear attachments as part of submission process clearAttachments(); posthog.capture("chat:home_submit"); }; if (!settings) { return null; // Or loading state } return ( <>
{/* Attachments list */} {/* Drag and drop overlay */}