Skip to content

Commit 8e3a711

Browse files
committed
fix: optimize conversation filtering and enhance cache synchronization by ensuring favorites are correctly handled in the ConversationList component
1 parent 1e2e221 commit 8e3a711

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/components/ConversationList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function ConversationList({
5555
}, [favoriteConversationIdsByCwd, cwd]);
5656

5757
const conversations = useMemo(() => {
58-
const base = (conversationsByCwd[cwd || ""] || []).slice().reverse();
58+
const base = (conversationsByCwd[cwd || ""] || []);
5959
const query = searchQuery.trim().toLowerCase();
6060
return base.filter((conv) => {
6161
if (mode === "favorites" && !favoriteIds.has(conv.conversationId)) {

src/stores/useConversationListStore.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ interface ConversationListActions {
2020
async function syncCacheToBackend(cwd: string) {
2121
const state = useConversationListStore.getState();
2222
const conversations = state.conversationsByCwd[cwd] ?? [];
23-
await invoke("write_project_cache", { projectPath: cwd, sessions: conversations, favorites: [] });
23+
const favorites = state.favoriteConversationIdsByCwd[cwd] ?? [];
24+
await invoke("write_project_cache", {
25+
projectPath: cwd,
26+
sessions: conversations,
27+
favorites
28+
});
2429
}
2530

2631
export const useConversationListStore = create<
@@ -170,17 +175,20 @@ export const useConversationListStore = create<
170175
// Helper to load project sessions from backend and update the store
171176
export async function loadProjectSessions(cwd: string) {
172177
const { sessions, favorites } = await invoke("load_project_sessions", { projectPath: cwd }) as { sessions: any[], favorites: string[] };
178+
173179
// Reset the store
174180
useConversationListStore.getState().reset();
175-
// Add each conversation/session
176-
for (const summary of sessions) {
177-
await useConversationListStore.getState().addConversation(cwd, summary);
178-
}
179-
// Set favorites for cwd
181+
182+
// First set the favorites to prevent them from being cleared during sync
180183
useConversationListStore.setState(state => ({
181184
favoriteConversationIdsByCwd: {
182185
...state.favoriteConversationIdsByCwd,
183186
[cwd]: favorites ?? [],
184187
}
185188
}));
186-
}
189+
190+
// Then add each conversation/session (this will sync with the correct favorites)
191+
for (const summary of sessions) {
192+
await useConversationListStore.getState().addConversation(cwd, summary);
193+
}
194+
}

0 commit comments

Comments
 (0)