chore: add inline message chat input

This commit is contained in:
Faisal Amir 2025-05-20 21:36:19 +07:00
parent 81c4dc516b
commit c0cef78ef2

View File

@ -16,6 +16,7 @@ import {
IconCodeCircle2, IconCodeCircle2,
IconPlayerStopFilled, IconPlayerStopFilled,
IconBrandSpeedtest, IconBrandSpeedtest,
IconX,
} from '@tabler/icons-react' } from '@tabler/icons-react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useGeneralSetting } from '@/hooks/useGeneralSetting' import { useGeneralSetting } from '@/hooks/useGeneralSetting'
@ -56,8 +57,16 @@ const ChatInput = ({
const { selectedModel } = useModelProvider() const { selectedModel } = useModelProvider()
const { sendMessage } = useChat() const { sendMessage } = useChat()
const [message, setMessage] = useState('')
console.log(model) const handleSendMesage = (prompt: string) => {
if (!selectedModel) {
setMessage('Please select a model to start chatting.')
return
}
setMessage('')
sendMessage(prompt)
}
useEffect(() => { useEffect(() => {
const handleFocusIn = () => { const handleFocusIn = () => {
@ -129,6 +138,7 @@ const ChatInput = ({
) )
return ( return (
<div className="relative">
<div className="relative"> <div className="relative">
<div <div
className={cn( className={cn(
@ -170,7 +180,7 @@ const ChatInput = ({
if (e.key === 'Enter' && !e.shiftKey && prompt) { if (e.key === 'Enter' && !e.shiftKey && prompt) {
e.preventDefault() e.preventDefault()
// Submit the message when Enter is pressed without Shift // Submit the message when Enter is pressed without Shift
sendMessage(prompt) handleSendMesage(prompt)
// When Shift+Enter is pressed, a new line is added (default behavior) // When Shift+Enter is pressed, a new line is added (default behavior)
} }
}} }}
@ -188,6 +198,7 @@ const ChatInput = ({
/> />
</div> </div>
</div> </div>
<div className="absolute z-20 bg-transparent bottom-0 w-full p-2 "> <div className="absolute z-20 bg-transparent bottom-0 w-full p-2 ">
<div className="flex justify-between items-center w-full"> <div className="flex justify-between items-center w-full">
<div className="px-1 flex items-center gap-1"> <div className="px-1 flex items-center gap-1">
@ -221,7 +232,10 @@ const ChatInput = ({
{selectedModel?.capabilities?.includes('embeddings') && ( {selectedModel?.capabilities?.includes('embeddings') && (
<div className="h-6 p-1 flex items-center justify-center rounded-sm hover:bg-main-view-fg/10 transition-all duration-200 ease-in-out gap-1"> <div className="h-6 p-1 flex items-center justify-center rounded-sm hover:bg-main-view-fg/10 transition-all duration-200 ease-in-out gap-1">
<IconCodeCircle2 size={18} className="text-main-view-fg/50" /> <IconCodeCircle2
size={18}
className="text-main-view-fg/50"
/>
</div> </div>
)} )}
@ -267,7 +281,7 @@ const ChatInput = ({
variant={!prompt ? null : 'default'} variant={!prompt ? null : 'default'}
size="icon" size="icon"
disabled={!prompt} disabled={!prompt}
onClick={() => sendMessage(prompt)} onClick={() => handleSendMesage(prompt)}
> >
{streamingContent ? ( {streamingContent ? (
<span className="animate-spin h-4 w-4 border-2 border-current border-t-transparent rounded-full" /> <span className="animate-spin h-4 w-4 border-2 border-current border-t-transparent rounded-full" />
@ -279,6 +293,20 @@ const ChatInput = ({
</div> </div>
</div> </div>
</div> </div>
{message && !selectedModel && (
<div className="bg-main-view-fg/2 -mt-0.5 mx-2 pb-2 px-3 pt-1.5 rounded-b-lg text-xs text-destructive transition-all duration-200 ease-in-out">
<div className="flex items-center gap-1 justify-between">
{message}
<IconX
className="size-3 text-main-view-fg/30 cursor-pointer"
onClick={() => {
setMessage('')
}}
/>
</div>
</div>
)}
</div>
) )
} }