Skip to content

Analytics Doesn't Refresh After Initial Load #39

@jacuzzicoding

Description

@jacuzzicoding

Bug Description

The analytics view only shows data from the initial load and doesn't update when changes are made to the donation status of items. Currently, there's no way for users to refresh the analytics data without restarting the app.

Current Behavior

  • Analytics data loads when first opening the analytics view
  • After marking items as donated/undonated, these changes aren't reflected in the analytics
  • There's no refresh button or mechanism to update the analytics view

Steps to Reproduce

  1. Open the app and navigate to the analytics view
  2. Note the current donation counts and percentages
  3. Exit analytics, mark several items as donated
  4. Return to the analytics view
  5. Observe that the analytics data hasn't updated to include the new donations

Expected Behavior

Either:

  1. The analytics view should automatically refresh when it becomes visible again, or
  2. A refresh button should be provided to allow users to manually update the analytics data

Possible Causes

In AnalyticsDashboardView.swift, data is only loaded on onAppear and when the currentTown changes, but not when returning to the view after making changes:

.onAppear {
    loadData()
}
.onChange(of: dataManager.currentTown) { _, _ in
    loadData()
}

Additionally, when marking items as donated, the analytics cache might not be properly invalidated.

Proposed Fix

  1. Add a refresh button to the AnalyticsDashboardView toolbar:
.toolbar {
    ToolbarItem {
        Button(action: {
            loadData()
        }) {
            Image(systemName: "arrow.clockwise")
        }
    }
}
  1. Ensure proper cache invalidation in DataManager.swift when donation status changes:
// In all updateXXXDonationStatus methods:
analyticsService.invalidateCache()

Priority

Medium - Affects functionality but there's a workaround (restarting the app)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions