From 8b4ce58c5699dd8cd0e77d0b818aeddfcf9a8a19 Mon Sep 17 00:00:00 2001 From: Illia Filippov <36344311+illia1f@users.noreply.github.com> Date: Sun, 28 Dec 2025 13:16:53 +0100 Subject: [PATCH] fix(ideation): update progress calculation to include just-completed ideation type (#381) Adjusted the progress calculation in the ideation store to account for the newly completed ideation type. This change ensures that the state updates are accurately reflected, especially with React 18's batching behavior. The updated logic now includes the completed type in the calculation of completed counts, improving the accuracy of progress tracking. Co-authored-by: Andy <119136210+AndyMik90@users.noreply.github.com> --- apps/frontend/src/renderer/stores/ideation-store.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/frontend/src/renderer/stores/ideation-store.ts b/apps/frontend/src/renderer/stores/ideation-store.ts index 81b07dce..08dee815 100644 --- a/apps/frontend/src/renderer/stores/ideation-store.ts +++ b/apps/frontend/src/renderer/stores/ideation-store.ts @@ -650,9 +650,16 @@ export function setupIdeationListeners(): () => void { store().addLog(`✓ ${ideationType} completed with ${ideas.length} ideas`); // Update progress based on completed types - const typeStates = store().typeStates; + // Calculate with the expected state since React 18 batches state updates. + // The Zustand update from addIdeasForType() is batched and won't be visible + // until after this event handler completes, so we manually include the + // just-completed type in the calculation. const config = store().config; - const completedCount = Object.entries(typeStates).filter( + const typeStates = store().typeStates; + + // Mark as completed in the calculation + const updatedStates = { ...typeStates, [ideationType]: 'completed' }; + const completedCount = Object.entries(updatedStates).filter( ([type, state]) => config.enabledTypes.includes(type as IdeationType) && (state === 'completed' || state === 'failed')