Skip to content

Commit 4f918f1

Browse files
fix the input section
1 parent c95041b commit 4f918f1

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/components/ChatInput.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,28 @@ const ChatInput: React.FC<ChatInputProps> = ({
3838
}) => {
3939
const textareaRef = useRef<HTMLTextAreaElement>(null);
4040
const [loadingTime, setLoadingTime] = useState(0);
41-
const loadingTimerRef = useRef<ReturnType<typeof setTimeout>>();
41+
const loadingTimerRef = useRef<ReturnType<typeof setInterval>>();
4242
const [activeButton, setActiveButton] = useState<"search" | "think" | null>(
4343
null
4444
);
4545

4646
useEffect(() => {
4747
if (isLoading) {
4848
setLoadingTime(0);
49-
loadingTimerRef.current = setTimeout(() => {
50-
setLoadingTime((prev) => prev + 1);
51-
}, 1000);
49+
const startTime = Date.now();
50+
loadingTimerRef.current = setInterval(() => {
51+
const elapsedMs = Date.now() - startTime;
52+
setLoadingTime(elapsedMs);
53+
}, 100); // Update more frequently for smoother display
5254
} else {
5355
if (loadingTimerRef.current) {
54-
clearTimeout(loadingTimerRef.current);
56+
clearInterval(loadingTimerRef.current);
5557
}
5658
setLoadingTime(0);
5759
}
5860
return () => {
5961
if (loadingTimerRef.current) {
60-
clearTimeout(loadingTimerRef.current);
62+
clearInterval(loadingTimerRef.current);
6163
}
6264
};
6365
}, [isLoading]);
@@ -127,6 +129,13 @@ const ChatInput: React.FC<ChatInputProps> = ({
127129
}
128130
};
129131

132+
const getLoadingTimeColor = () => {
133+
if (loadingTime < 5000) return "text-green-400"; // Less than 5s - green
134+
if (loadingTime < 10000) return "text-yellow-400"; // 5-10s - yellow
135+
if (loadingTime < 15000) return "text-sky-400"; // 10-15s - sky blue
136+
return "text-red-400"; // More than 15s - red
137+
};
138+
130139
return (
131140
<div className="fixed bottom-0 left-0 right-0 z-40 flex flex-col items-center w-full">
132141
<div className="relative w-full px-2 pb-3 sm:pb-4">
@@ -228,17 +237,25 @@ const ChatInput: React.FC<ChatInputProps> = ({
228237
<button
229238
type="submit"
230239
disabled={isLoading || !message.trim()}
231-
className="group flex justify-center items-center h-9 w-9 rounded-full bg-gray-800 text-gray-400 hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
240+
className="group flex justify-center items-center h-9 w-9 rounded-full bg-gray-800 text-gray-400 hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed relative z-10"
241+
style={{ cursor: "pointer" }}
232242
>
243+
{/* Invisible larger hit area */}
244+
<span className="absolute inset-0 -m-3 rounded-full pointer-events-auto" />
245+
233246
{isLoading ? (
234247
<>
235-
<Loader2 className="w-5 h-5 animate-spin" />
236-
<span className="absolute -top-6 left-1/2 transform -translate-x-1/2 text-xs text-gray-400">
237-
{loadingTime}s
248+
<Loader2
249+
className={`w-5 h-5 animate-spin ${getLoadingTimeColor()}`}
250+
/>
251+
<span
252+
className={`absolute -top-6 left-1/2 transform -translate-x-1/2 text-xs ${getLoadingTimeColor()} transition-colors`}
253+
>
254+
{(loadingTime / 1000).toFixed(1)}s
238255
</span>
239256
</>
240257
) : (
241-
<Send className="w-5 h-5" />
258+
<Send className="w-5 h-5 pointer-events-none" />
242259
)}
243260
</button>
244261
</div>

0 commit comments

Comments
 (0)