Skip to content

Commit c7e6b9f

Browse files
committed
perf: simplify conversation title display to avoid IndexedDB queries
- Remove IndexedDB queries for conversation titles in sidebar - Display only chat index numbers to improve performance - Eliminate async operations and unnecessary component state
1 parent 8c7d7b9 commit c7e6b9f

File tree

1 file changed

+2
-44
lines changed

1 file changed

+2
-44
lines changed

src/components/ConversationTitle..tsx

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,13 @@
1-
import { STORAGE_NAME } from "@/const";
21
import { AppChatStoreContext, AppContext } from "@/pages/App";
3-
import { ChatStore } from "@/types/chatstore";
42
import {
53
memo,
64
useContext,
7-
useEffect,
8-
useMemo,
9-
useState,
10-
useCallback,
115
} from "react";
126

137
const ConversationTitle = ({ chatStoreIndex }: { chatStoreIndex: number }) => {
14-
const { db, selectedChatIndex } = useContext(AppContext);
15-
const [title, setTitle] = useState("");
16-
17-
const getTitle = useCallback(async () => {
18-
try {
19-
const chatStore = (await (
20-
await db
21-
).get(STORAGE_NAME, chatStoreIndex)) as ChatStore;
22-
23-
if (chatStore.history.length === 0) {
24-
setTitle(`${chatStoreIndex}`);
25-
return;
26-
}
27-
28-
const content = chatStore.history[0]?.content;
29-
if (!content) {
30-
setTitle(`${chatStoreIndex}`);
31-
return;
32-
}
33-
34-
if (typeof content === "string") {
35-
setTitle(content.substring(0, 39));
36-
}
37-
} catch (e) {
38-
console.error(e);
39-
}
40-
}, [db, chatStoreIndex]);
41-
42-
useEffect(() => {
43-
getTitle();
44-
}, [getTitle]);
45-
46-
const handleClick = useCallback(() => {
47-
getTitle();
48-
}, [getTitle]);
49-
508
return (
51-
<span className="w-full" onClick={handleClick}>
52-
{title}
9+
<span className="w-full">
10+
{chatStoreIndex}
5311
</span>
5412
);
5513
};

0 commit comments

Comments
 (0)