|
1 | | -import { Box, Static, Text } from "ink"; |
2 | | -import Spinner from "ink-spinner"; |
3 | | -import TextInput from "ink-text-input"; |
| 1 | +import { Box } from "ink"; |
4 | 2 | import type React from "react"; |
5 | 3 | import { useState } from "react"; |
6 | | - |
7 | | -interface Message { |
8 | | - id: number; |
9 | | - text: string; |
10 | | - sender: "user" | "cat"; |
11 | | -} |
| 4 | +import { ChatHistory } from "./components/ChatHistory"; |
| 5 | +import { InputField } from "./components/InputField"; |
| 6 | +import { Spinner } from "./components/Spinner"; |
| 7 | +import type { Message } from "./components/types"; |
12 | 8 |
|
13 | 9 | export const App: React.FC = () => { |
14 | 10 | const [messages, setMessages] = useState<Message[]>([]); |
@@ -41,30 +37,14 @@ export const App: React.FC = () => { |
41 | 37 |
|
42 | 38 | return ( |
43 | 39 | <Box flexDirection="column"> |
44 | | - <Static items={messages}> |
45 | | - {(message) => ( |
46 | | - <Box key={message.id} marginBottom={1}> |
47 | | - <Text color={message.sender === "user" ? "cyan" : "green"}> |
48 | | - {message.text} |
49 | | - </Text> |
50 | | - </Box> |
51 | | - )} |
52 | | - </Static> |
53 | | - {isLoading && ( |
54 | | - <Box> |
55 | | - <Spinner type="dots" /> |
56 | | - <Text> Thinking...</Text> |
57 | | - </Box> |
58 | | - )} |
59 | | - <Box> |
60 | | - <Text color="yellow">> </Text> |
61 | | - <TextInput |
62 | | - value={input} |
63 | | - onChange={setInput} |
64 | | - onSubmit={handleSubmit} |
65 | | - showCursor={!isLoading} |
66 | | - /> |
67 | | - </Box> |
| 40 | + <ChatHistory messages={messages} /> |
| 41 | + {isLoading && <Spinner />} |
| 42 | + <InputField |
| 43 | + value={input} |
| 44 | + onChange={setInput} |
| 45 | + onSubmit={handleSubmit} |
| 46 | + showCursor={!isLoading} |
| 47 | + /> |
68 | 48 | </Box> |
69 | 49 | ); |
70 | 50 | }; |
0 commit comments