()
| 6 | |
| 7 | // Chat input is disabled if no files are uploaded |
| 8 | const ChatInput = () => { |
| 9 | const [value, setValue] = useState(''); |
| 10 | |
| 11 | const sendChat = useChatStore((state) => state.sendChat); |
| 12 | const loading = useChatStore((state) => state.loading); |
| 13 | const error = useChatStore((state) => state.error); |
| 14 | const toast = useToast(); |
| 15 | const files = useFilesStore((state) => state.files); |
| 16 | const chatDisabled = !files || files.length === 0; |
| 17 | |
| 18 | const handleSend = async () => { |
| 19 | if (!value.trim() || loading || chatDisabled) return; // Disable send if no files are uploaded |
| 20 | await sendChat(value); |
| 21 | setValue(''); |
| 22 | }; |
| 23 | |
| 24 | // Show error toast if error changes |
| 25 | React.useEffect(() => { |
| 26 | if (error) { |
| 27 | toast({ |
| 28 | title: 'Chat Error', |
| 29 | description: error, |
| 30 | status: 'error', |
| 31 | duration: 4000, |
| 32 | isClosable: true, |
| 33 | position: 'top', |
| 34 | }); |
| 35 | } |
| 36 | }, [error, toast]); |
| 37 | |
| 38 | return ( |
| 39 | <HStack spacing={2}> |
| 40 | |
| 41 | <Input |
| 42 | value={value} |
| 43 | onChange={(e) => setValue(e.target.value)} |
| 44 | placeholder={chatDisabled ? 'Please upload a file to start chatting' : 'Type your message...'} |
| 45 | isDisabled={chatDisabled || loading} |
| 46 | onKeyDown={(e) => { |
| 47 | if (e.key === 'Enter') handleSend(); |
| 48 | }} |
| 49 | /> |
| 50 | <IconButton |
| 51 | aria-label="Send" |
| 52 | icon={loading ? <Spinner size="sm" /> : <FaPaperPlane />} |
| 53 | onClick={handleSend} |
| 54 | isDisabled={chatDisabled || loading || !value.trim()} |
| 55 | colorScheme="blue" |
| 56 | /> |
| 57 | </HStack> |
| 58 | ); |
| 59 | }; |
| 60 | |
| 61 | export default ChatInput; |
nothing calls this directly
no test coverage detected