@@ -20,7 +20,12 @@ interface ConversationListActions {
2020async 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
2631export const useConversationListStore = create <
@@ -170,17 +175,20 @@ export const useConversationListStore = create<
170175// Helper to load project sessions from backend and update the store
171176export 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