From 1c8a3e14623aea0b86c30e6e801c6c462f98ac3f Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Thu, 16 Mar 2023 23:36:19 +0800 Subject: [PATCH] prevent selectChatIndex -1 error --- src/app.tsx | 2 +- src/chatbox.tsx | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app.tsx b/src/app.tsx index d436bda..2ab83fd 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -129,7 +129,7 @@ export function App() { ); setSelectedChatIndex(0); } else { - setSelectedChatIndex(selectedChatIndex - 1); + setSelectedChatIndex(Math.max(selectedChatIndex - 1, 0)); } setAllChatStore([...allChatStore]); }} diff --git a/src/chatbox.tsx b/src/chatbox.tsx index d3efda7..582cd0c 100644 --- a/src/chatbox.tsx +++ b/src/chatbox.tsx @@ -8,6 +8,8 @@ export default function ChatBOX(props: { setChatStore: (cs: ChatStore) => void; }) { const { chatStore, setChatStore } = props; + // prevent error + if (chatStore === undefined) return
; const [inputMsg, setInputMsg] = useState(""); const [showGenerating, setShowGenerating] = useState(false); const [generatingMessage, setGeneratingMessage] = useState("");