@@ -75,6 +75,24 @@ export default function ChatArea({ conversation, character, onConversationUpdate
|
||||
scrollToBottom()
|
||||
}, [messages])
|
||||
|
||||
// 监听状态栏按钮点击事件
|
||||
useEffect(() => {
|
||||
const handleStatusBarAction = (event: CustomEvent) => {
|
||||
const action = event.detail
|
||||
if (action && typeof action === 'string' && !sending) {
|
||||
console.log('[ChatArea] 收到状态栏操作,自动发送消息:', action)
|
||||
setInputValue(action)
|
||||
// 延迟发送,确保 inputValue 已更新
|
||||
setTimeout(() => {
|
||||
handleSendMessage(action)
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('sendMessageFromStatusBar', handleStatusBarAction as EventListener)
|
||||
return () => window.removeEventListener('sendMessageFromStatusBar', handleStatusBarAction as EventListener)
|
||||
}, [sending])
|
||||
|
||||
const loadMessages = async () => {
|
||||
try {
|
||||
setLoading(true)
|
||||
@@ -185,11 +203,10 @@ export default function ChatArea({ conversation, character, onConversationUpdate
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const handleSend = async () => {
|
||||
if (!inputValue.trim() || sending) return
|
||||
const handleSendMessage = async (message: string) => {
|
||||
if (!message.trim() || sending) return
|
||||
|
||||
const userMessage = inputValue.trim()
|
||||
setInputValue('')
|
||||
const userMessage = message.trim()
|
||||
setSending(true)
|
||||
|
||||
const tempUserMessage: Message = {
|
||||
@@ -277,6 +294,13 @@ export default function ChatArea({ conversation, character, onConversationUpdate
|
||||
}
|
||||
}
|
||||
|
||||
const handleSend = async () => {
|
||||
if (!inputValue.trim() || sending) return
|
||||
const userMessage = inputValue.trim()
|
||||
setInputValue('')
|
||||
await handleSendMessage(userMessage)
|
||||
}
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey && !sending && inputValue.trim()) {
|
||||
e.preventDefault()
|
||||
@@ -644,7 +668,7 @@ export default function ChatArea({ conversation, character, onConversationUpdate
|
||||
>
|
||||
<MessageContent
|
||||
content={msg.content}
|
||||
role={msg.role}
|
||||
role={msg.role as 'user' | 'assistant'}
|
||||
onChoiceSelect={(choice) => {
|
||||
setInputValue(choice)
|
||||
textareaRef.current?.focus()
|
||||
|
||||
Reference in New Issue
Block a user