Fix stuck "Generating Insights" modal overlay

Set all three loading states to .loading upfront before entering the
task group, and remove .idle from the modal visibility condition. This
prevents the overlay from staying visible when tasks complete at
different rates while others remain in .idle state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Trey T
2026-04-05 19:43:32 -05:00
parent 5fd50e1a84
commit e6a34a0f25
2 changed files with 7 additions and 1 deletions

View File

@@ -293,7 +293,7 @@ struct InsightsView: View {
private var isGeneratingInsights: Bool { private var isGeneratingInsights: Bool {
let states = [viewModel.monthLoadingState, viewModel.yearLoadingState, viewModel.allTimeLoadingState] let states = [viewModel.monthLoadingState, viewModel.yearLoadingState, viewModel.allTimeLoadingState]
return states.contains(where: { $0 == .loading || $0 == .idle }) return states.contains(where: { $0 == .loading })
} }
private var generatingOverlay: some View { private var generatingOverlay: some View {

View File

@@ -132,6 +132,12 @@ class InsightsViewModel: ObservableObject {
} }
} }
// Set all states to loading upfront so the overlay dismisses
// as soon as all tasks complete (not one-by-one)
monthLoadingState = .loading
yearLoadingState = .loading
allTimeLoadingState = .loading
// Generate insights concurrently for all three periods // Generate insights concurrently for all three periods
await withTaskGroup(of: Void.self) { group in await withTaskGroup(of: Void.self) { group in
group.addTask { @MainActor in group.addTask { @MainActor in