select chat index after fetch

This commit is contained in:
2023-03-29 15:37:36 +08:00
parent c31c6cd84a
commit 5fc2c62b4f
2 changed files with 11 additions and 3 deletions

View File

@@ -205,7 +205,12 @@ export function App() {
DEL DEL
</button> </button>
</div> </div>
<ChatBOX chatStore={chatStore} setChatStore={setChatStore} /> <ChatBOX
chatStore={chatStore}
setChatStore={setChatStore}
selectedChatIndex={selectedChatIndex}
setSelectedChatIndex={setSelectedChatIndex}
/>
</div> </div>
); );
} }

View File

@@ -1,5 +1,5 @@
import { createRef } from "preact"; import { createRef } from "preact";
import { useEffect, useState } from "preact/hooks"; import { StateUpdater, useEffect, useState } from "preact/hooks";
import type { ChatStore } from "./app"; import type { ChatStore } from "./app";
import ChatGPT, { ChunkMessage, FetchResponse } from "./chatgpt"; import ChatGPT, { ChunkMessage, FetchResponse } from "./chatgpt";
import Message from "./message"; import Message from "./message";
@@ -8,6 +8,8 @@ import Settings from "./settings";
export default function ChatBOX(props: { export default function ChatBOX(props: {
chatStore: ChatStore; chatStore: ChatStore;
setChatStore: (cs: ChatStore) => void; setChatStore: (cs: ChatStore) => void;
selectedChatIndex: number;
setSelectedChatIndex: StateUpdater<number>;
}) { }) {
const { chatStore, setChatStore } = props; const { chatStore, setChatStore } = props;
// prevent error // prevent error
@@ -134,6 +136,7 @@ export default function ChatBOX(props: {
alert(error); alert(error);
} finally { } finally {
setShowGenerating(false); setShowGenerating(false);
props.setSelectedChatIndex(props.selectedChatIndex);
} }
}; };
@@ -205,7 +208,7 @@ export default function ChatBOX(props: {
<br /> <br />
Endpoint: {chatStore.apiEndpoint} Endpoint: {chatStore.apiEndpoint}
<br /> <br />
<br /> <br />
NEW NEW
<br /> <br />