import styles from './chatInputArea.module.css'; import React, { useEffect, useRef, useState } from 'react'; import { uploadDataForIndexing } from '../../common/chatFunctions'; import { Progress } from "@/components/ui/progress" import 'katex/dist/katex.min.css'; import { ArrowCircleUp, ArrowRight, Browser, ChatsTeardrop, FileArrowUp, GlobeSimple, Gps, Image, Microphone, Notebook, Question, Robot, Shapes } from '@phosphor-icons/react'; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from "@/components/ui/command" import { Textarea } from "@/components/ui/textarea" import { Button } from '@/components/ui/button'; import { AlertDialog, AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog'; import { Popover, PopoverContent } from '@/components/ui/popover'; import { PopoverTrigger } from '@radix-ui/react-popover'; export interface ChatOptions { [key: string]: string } interface ChatInputProps { sendMessage: (message: string) => void; sendDisabled: boolean; setUploadedFiles?: (files: string[]) => void; conversationId?: string | null; chatOptionsData?: ChatOptions | null; isMobileWidth?: boolean; isLoggedIn: boolean; } export default function ChatInputArea(props: ChatInputProps) { const [message, setMessage] = useState(''); const fileInputRef = useRef(null); const [warning, setWarning] = useState(null); const [error, setError] = useState(null); const [uploading, setUploading] = useState(false); const [progressValue, setProgressValue] = useState(0); useEffect(() => { if (!uploading) { setProgressValue(0); } if (uploading) { const interval = setInterval(() => { setProgressValue((prev) => { const increment = Math.floor(Math.random() * 5) + 1; // Generates a random number between 1 and 5 const nextValue = prev + increment; return nextValue < 100 ? nextValue : 100; // Ensures progress does not exceed 100 }); }, 800); return () => clearInterval(interval); } }, [uploading]); function onSendMessage() { props.sendMessage(message); setMessage(''); } function handleSlashCommandClick(command: string) { setMessage(`/${command} `); } function handleFileButtonClick() { if (!fileInputRef.current) return; fileInputRef.current.click(); } function handleFileChange(event: React.ChangeEvent) { if (!event.target.files) return; uploadDataForIndexing( event.target.files, setWarning, setUploading, setError, props.setUploadedFiles, props.conversationId); } function getIconForSlashCommand(command: string) { if (command.includes('summarize')) { return } if (command.includes('help')) { return } if (command.includes('automation')) { return } if (command.includes('webpage')) { return } if (command.includes('notes')) { return } if (command.includes('image')) { return } if (command.includes('default')) { return } if (command.includes('general')) { return } if (command.includes('online')) { return } return } return ( <> { uploading && ( Uploading data. Please wait. setUploading(false)}>Dismiss )} { warning && ( Data Upload Warning {warning} setWarning(null)}>Close ) } { error && ( Oh no! Something went wrong while uploading your data {error} setError(null)}>Close ) } { (message.startsWith('/') && message.split(' ').length === 1) &&
e.preventDefault()} className={`${props.isMobileWidth ? 'w-[100vw]' : 'w-full'} rounded-md`}> No matching commands. {props.chatOptionsData && Object.entries(props.chatOptionsData).map(([key, value]) => ( handleSlashCommandClick(key)}>
{getIconForSlashCommand(key)} /{key}
{value}
))}
}