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:
@@ -293,7 +293,7 @@ struct InsightsView: View {
|
||||
|
||||
private var isGeneratingInsights: Bool {
|
||||
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 {
|
||||
|
||||
@@ -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
|
||||
await withTaskGroup(of: Void.self) { group in
|
||||
group.addTask { @MainActor in
|
||||
|
||||
Reference in New Issue
Block a user