Skip to content

Commit 12daf7c

Browse files
koki-developclaude
andcommitted
feat: add spinner during cat response
- Add loading state management - Display "Thinking..." spinner while waiting for cat response - Disable input cursor during loading - Prevent duplicate submissions while loading 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 209a741 commit 12daf7c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/App.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Box, Static, Text } from "ink";
2+
import Spinner from "ink-spinner";
23
import TextInput from "ink-text-input";
34
import type React from "react";
45
import { useState } from "react";
@@ -12,9 +13,10 @@ interface Message {
1213
export const App: React.FC = () => {
1314
const [messages, setMessages] = useState<Message[]>([]);
1415
const [input, setInput] = useState("");
16+
const [isLoading, setIsLoading] = useState(false);
1517

1618
const handleSubmit = () => {
17-
if (input.trim() === "") return;
19+
if (input.trim() === "" || isLoading) return;
1820

1921
const newMessage: Message = {
2022
id: messages.length + 1,
@@ -24,6 +26,7 @@ export const App: React.FC = () => {
2426

2527
setMessages([...messages, newMessage]);
2628
setInput("");
29+
setIsLoading(true);
2730

2831
setTimeout(() => {
2932
const response: Message = {
@@ -32,6 +35,7 @@ export const App: React.FC = () => {
3235
sender: "cat",
3336
};
3437
setMessages((prev) => [...prev, response]);
38+
setIsLoading(false);
3539
}, 500);
3640
};
3741

@@ -46,9 +50,20 @@ export const App: React.FC = () => {
4650
</Box>
4751
)}
4852
</Static>
53+
{isLoading && (
54+
<Box>
55+
<Spinner type="dots" />
56+
<Text> Thinking...</Text>
57+
</Box>
58+
)}
4959
<Box>
5060
<Text color="yellow">&gt; </Text>
51-
<TextInput value={input} onChange={setInput} onSubmit={handleSubmit} />
61+
<TextInput
62+
value={input}
63+
onChange={setInput}
64+
onSubmit={handleSubmit}
65+
showCursor={!isLoading}
66+
/>
5267
</Box>
5368
</Box>
5469
);

0 commit comments

Comments
 (0)