|
1 | 1 | import { useState } from "preact/hooks"; |
2 | 2 | import type { ChatStore } from "./app"; |
3 | 3 | import ChatGPT, { ChunkMessage } from "./chatgpt"; |
| 4 | +import Message from "./message"; |
4 | 5 | import Settings from "./settings"; |
5 | 6 |
|
6 | 7 | export default function ChatBOX(props: { |
@@ -184,51 +185,13 @@ export default function ChatBOX(props: { |
184 | 185 | 暂无历史对话记录 |
185 | 186 | </p> |
186 | 187 | )} |
187 | | - {chatStore.history.map((chat, i) => { |
188 | | - const pClassName = |
189 | | - chat.role === "assistant" |
190 | | - ? "p-2 rounded relative bg-white my-2 text-left dark:bg-gray-700 dark:text-white" |
191 | | - : "p-2 rounded relative bg-green-400 my-2 text-right"; |
192 | | - const iconClassName = |
193 | | - chat.role === "user" |
194 | | - ? "absolute bottom-0 left-0" |
195 | | - : "absolute bottom-0 right-0"; |
196 | | - const DeleteIcon = () => ( |
197 | | - <button |
198 | | - className={iconClassName} |
199 | | - onClick={() => { |
200 | | - if ( |
201 | | - confirm( |
202 | | - `Are you sure to delete this message?\n${chat.content.slice( |
203 | | - 0, |
204 | | - 39 |
205 | | - )}...` |
206 | | - ) |
207 | | - ) { |
208 | | - chatStore.history.splice(i, 1); |
209 | | - chatStore.postBeginIndex = Math.max( |
210 | | - chatStore.postBeginIndex - 1, |
211 | | - 0 |
212 | | - ); |
213 | | - setChatStore({ ...chatStore }); |
214 | | - } |
215 | | - }} |
216 | | - > |
217 | | - 🗑️ |
218 | | - </button> |
219 | | - ); |
220 | | - return ( |
221 | | - <p className={pClassName}> |
222 | | - {chat.content |
223 | | - .split("\n") |
224 | | - .filter((line) => line) |
225 | | - .map((line) => ( |
226 | | - <p className="my-1">{line}</p> |
227 | | - ))} |
228 | | - <DeleteIcon /> |
229 | | - </p> |
230 | | - ); |
231 | | - })} |
| 188 | + {chatStore.history.map((_, messageIndex) => ( |
| 189 | + <Message |
| 190 | + chatStore={chatStore} |
| 191 | + setChatStore={setChatStore} |
| 192 | + messageIndex={messageIndex} |
| 193 | + /> |
| 194 | + ))} |
232 | 195 | {showGenerating && ( |
233 | 196 | <p className="p-2 my-2 animate-pulse dark:text-white"> |
234 | 197 | {generatingMessage |
|
0 commit comments