prevent selectChatIndex -1 error

This commit is contained in:
2023-03-16 23:36:19 +08:00
parent 772e9ac612
commit 1c8a3e1462
2 changed files with 3 additions and 1 deletions

View File

@@ -129,7 +129,7 @@ export function App() {
); );
setSelectedChatIndex(0); setSelectedChatIndex(0);
} else { } else {
setSelectedChatIndex(selectedChatIndex - 1); setSelectedChatIndex(Math.max(selectedChatIndex - 1, 0));
} }
setAllChatStore([...allChatStore]); setAllChatStore([...allChatStore]);
}} }}

View File

@@ -8,6 +8,8 @@ export default function ChatBOX(props: {
setChatStore: (cs: ChatStore) => void; setChatStore: (cs: ChatStore) => void;
}) { }) {
const { chatStore, setChatStore } = props; const { chatStore, setChatStore } = props;
// prevent error
if (chatStore === undefined) return <div></div>;
const [inputMsg, setInputMsg] = useState(""); const [inputMsg, setInputMsg] = useState("");
const [showGenerating, setShowGenerating] = useState(false); const [showGenerating, setShowGenerating] = useState(false);
const [generatingMessage, setGeneratingMessage] = useState(""); const [generatingMessage, setGeneratingMessage] = useState("");