From f278e5b1fc22f7e7b4c43d284888f0c401d31d1d Mon Sep 17 00:00:00 2001
From: heimoshuiyu
Date: Wed, 22 Mar 2023 15:39:25 +0800
Subject: [PATCH] split message.tsx
---
src/chatbox.tsx | 53 ++++++++-----------------------------------------
src/message.tsx | 51 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 45 deletions(-)
create mode 100644 src/message.tsx
diff --git a/src/chatbox.tsx b/src/chatbox.tsx
index 16c2edf..17c9a43 100644
--- a/src/chatbox.tsx
+++ b/src/chatbox.tsx
@@ -1,6 +1,7 @@
import { useState } from "preact/hooks";
import type { ChatStore } from "./app";
import ChatGPT, { ChunkMessage } from "./chatgpt";
+import Message from "./message";
import Settings from "./settings";
export default function ChatBOX(props: {
@@ -184,51 +185,13 @@ export default function ChatBOX(props: {
暂无历史对话记录
)}
- {chatStore.history.map((chat, i) => {
- const pClassName =
- chat.role === "assistant"
- ? "p-2 rounded relative bg-white my-2 text-left dark:bg-gray-700 dark:text-white"
- : "p-2 rounded relative bg-green-400 my-2 text-right";
- const iconClassName =
- chat.role === "user"
- ? "absolute bottom-0 left-0"
- : "absolute bottom-0 right-0";
- const DeleteIcon = () => (
-
- );
- return (
-
- {chat.content
- .split("\n")
- .filter((line) => line)
- .map((line) => (
-
{line}
- ))}
-
-
- );
- })}
+ {chatStore.history.map((_, messageIndex) => (
+
+ ))}
{showGenerating && (
{generatingMessage
diff --git a/src/message.tsx b/src/message.tsx
new file mode 100644
index 0000000..a1b7552
--- /dev/null
+++ b/src/message.tsx
@@ -0,0 +1,51 @@
+import { ChatStore } from "./app";
+
+interface Props {
+ messageIndex: number;
+ chatStore: ChatStore;
+ setChatStore: (cs: ChatStore) => void;
+}
+export default function Message(props: Props) {
+ const { chatStore, messageIndex, setChatStore } = props;
+ const chat = chatStore.history[messageIndex];
+ const pClassName =
+ chat.role === "assistant"
+ ? "p-2 rounded relative bg-white my-2 text-left dark:bg-gray-700 dark:text-white"
+ : "p-2 rounded relative bg-green-400 my-2 text-right";
+ const iconClassName =
+ chat.role === "user"
+ ? "absolute bottom-0 left-0"
+ : "absolute bottom-0 right-0";
+ const DeleteIcon = () => (
+
+ );
+ return (
+
+ {chat.content
+ .split("\n")
+ .filter((line) => line)
+ .map((line) => (
+
{line}
+ ))}
+
+
+ );
+}