Skip to content

Commit 2328ace

Browse files
committed
feat: sort conversations by timestamp in ConversationList and update conversation merging logic in useConversationListStore
1 parent 7f72569 commit 2328ace

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/components/ConversationList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ export function ConversationList({
9898

9999
const conversations = useMemo(() => {
100100
const base = conversationsByCwd[cwd || ""] || [];
101+
const sorted = [...base].sort((a, b) => {
102+
const aTime = a.timestamp ? new Date(a.timestamp).getTime() : 0;
103+
const bTime = b.timestamp ? new Date(b.timestamp).getTime() : 0;
104+
return bTime - aTime;
105+
});
101106
const query = searchQuery.trim().toLowerCase();
102-
return base.filter((conv) => {
107+
return sorted.filter((conv) => {
103108
if (mode === "favorites" && !favoriteIds.has(conv.conversationId)) {
104109
return false;
105110
}

src/stores/useConversationListStore.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ export const useConversationListStore = create<
5050
existingItem?.timestamp ??
5151
new Date().toISOString(),
5252
};
53-
const nextList =
54-
index >= 0
55-
? existingList.map((item, idx) =>
56-
idx === index ? { ...item, ...summaryWithTimestamp } : item,
57-
)
58-
: [...existingList, summaryWithTimestamp];
53+
const mergedConversation =
54+
existingItem === null
55+
? summaryWithTimestamp
56+
: { ...existingItem, ...summaryWithTimestamp };
57+
const nextList = [
58+
mergedConversation,
59+
...existingList.filter(
60+
(item) => item.conversationId !== summaryWithTimestamp.conversationId,
61+
),
62+
];
5963

6064
return {
6165
conversationsByCwd: {

0 commit comments

Comments
 (0)