refactor(chat): simplify input send button

This commit is contained in:
2026-07-01 12:42:26 +08:00
parent a80d68c1e4
commit eccb6d3074
3 changed files with 7 additions and 70 deletions
+3 -45
View File
@@ -2,11 +2,9 @@
import { useRef, useState } from "react";
import { useChatDispatch } from "@/stores/chat/chat-context";
import { useUserState } from "@/stores/user/user-context";
import { useKeyboardHeight } from "@/hooks";
import { Logger } from "@/utils";
import { ChatInputActionPanel } from "./chat-input-action-panel";
import { ChatInputTextField } from "./chat-input-text-field";
import { ChatSendButton } from "./chat-send-button";
import styles from "./chat-input-bar.module.css";
@@ -19,15 +17,11 @@ export interface ChatInputBarProps {
export function ChatInputBar({ disabled = false }: ChatInputBarProps) {
const dispatch = useChatDispatch();
const { currentUser } = useUserState();
const [input, setInput] = useState("");
const [isFocused, setIsFocused] = useState(false);
const [isActionPanelOpen, setIsActionPanelOpen] = useState(false);
const textareaRef = useRef<HTMLTextAreaElement>(null);
const hasContent = input.trim().length > 0;
const isActive = isFocused || isActionPanelOpen;
const voiceMinutesRemaining = currentUser?.voiceMinutesRemaining ?? 0;
useKeyboardHeight({
targetRef: textareaRef,
@@ -37,9 +31,6 @@ export function ChatInputBar({ disabled = false }: ChatInputBarProps) {
const handleInputChange = (value: string) => {
setInput(value);
if (value.trim().length > 0) {
setIsActionPanelOpen(false);
}
};
const handleSend = () => {
@@ -56,34 +47,9 @@ export function ChatInputBar({ disabled = false }: ChatInputBarProps) {
textareaRef.current?.focus();
};
const handleActionButtonClick = () => {
if (hasContent) {
handleSend();
return;
}
textareaRef.current?.blur();
setIsFocused(false);
setIsActionPanelOpen((open) => !open);
};
const handleVoiceMessageClick = () => {
log.debug("[chat-input-bar] voice message action clicked", {
voiceMinutesRemaining,
});
};
return (
<div
className={`${styles.bar} ${isActive ? styles.barFocused : ""} ${
isActionPanelOpen ? styles.barExpanded : ""
}`}
>
<div
className={`${styles.row} ${isActive ? styles.rowFocused : ""} ${
isActionPanelOpen ? styles.rowExpanded : ""
}`}
>
<div className={`${styles.bar} ${isFocused ? styles.barFocused : ""}`}>
<div className={`${styles.row} ${isFocused ? styles.rowFocused : ""}`}>
<ChatInputTextField
ref={textareaRef}
value={input}
@@ -94,17 +60,9 @@ export function ChatInputBar({ disabled = false }: ChatInputBarProps) {
/>
<ChatSendButton
disabled={disabled}
hasContent={hasContent}
isExpanded={isActionPanelOpen}
onClick={handleActionButtonClick}
onClick={handleSend}
/>
</div>
{isActionPanelOpen ? (
<ChatInputActionPanel
voiceMinutesRemaining={voiceMinutesRemaining}
onVoiceMessageClick={handleVoiceMessageClick}
/>
) : null}
</div>
);
}