Skip to content

feat: global health data sync and comprehensive UI refresh fixes#718

Merged
CodeWithCJ merged 7 commits intomainfrom
dev
Feb 22, 2026
Merged

feat: global health data sync and comprehensive UI refresh fixes#718
CodeWithCJ merged 7 commits intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

Summary
This PR addresses synchronization reliability, improves UI data freshness, and introduces a new global "Sync All" feature. It resolves the issue where the Diary page required a manual browser refresh to display newly synced data and hardens the backend against integration data errors.

Changes

  1. Global Synchronization (Frontend)

New Feature: Added a "Sync All" button to the application header. It automatically detects all active manual-sync providers (Strava, Fitbit, Polar, Withings, Garmin, Hevy) and triggers them sequentially.
Refactoring: Extracted sync orchestration and cache invalidation logic into a new shared
useSyncAll
hook.
Internationalization: Added English translation keys for the new global sync UI and notifications.
2. Cache & UI Freshness (Frontend)

Global Config Fix: Updated
App.tsx
to enable refetchOnMount and refetchOnWindowFocus in the global QueryClient defaults. This ensures that invalidated/stale data is actually refetched when the user navigates back to the Diary.
Unified Invalidation: Implemented a robust invalidateSyncData helper that triggers a refresh for Exercises, Daily Progress (Calories/Steps), Measurements (Weight), and Sleep data.
Integration Hardening: Applied the invalidation logic to all manual sync points in
ExternalProviderSettings
and all OAuth linking hooks in
useIntegrations.ts
.
3. Integration Robustness (Backend)

Model Hardening: Updated exerciseEntry.js to include default values (e.g., 0 for calories_burned), preventing NOT NULL violations if an external API sends incomplete data.
Processor Improvements: Hardened Strava, Fitbit, and Hevy data processors to handle specific API quirks and ensure data integrity during synchronization.
Verification Results
UI Refresh: Confirmed that data updates immediately on the Diary page after a "Sync All" or manual sync completes, with no browser refresh required.
"Sync All" Button: Verified the sequential triggering of multiple providers and the summary toast notification.
Database Safety: Verified that activities with missing fields no longer cause server-side crashes during ingestion.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CodeWithCJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the application's data synchronization capabilities and user experience. It introduces a convenient global "Sync All" feature, allowing users to refresh data from all connected external providers with a single click. Concurrently, it addresses UI data freshness issues, ensuring that newly synced information is immediately reflected without requiring manual page reloads. Furthermore, the backend has been fortified to handle incomplete data from external APIs more gracefully, improving overall system reliability.

Highlights

  • Global "Sync All" Feature: Introduced a new button to trigger sequential synchronization across all active manual-sync providers (Strava, Fitbit, Polar, Withings, Garmin, Hevy).
  • Improved UI Freshness: Eliminated the need for manual browser refreshes on the Diary page by enabling refetchOnMount and refetchOnWindowFocus in the global QueryClient defaults, ensuring data updates immediately.
  • Robust Data Invalidation: Implemented a unified invalidateSyncData helper and applied it to all manual sync points and OAuth linking hooks, ensuring consistent and comprehensive data updates across the application.
  • Backend Integration Hardening: Enhanced data processors for Fitbit, Hevy, and Strava, and updated exerciseEntry.js to prevent NOT NULL violations by providing default values (e.g., 0 for calories_burned) for potentially incomplete data from external APIs.
Changelog
  • SparkyFitnessFrontend/public/locales/en/translation.json
    • Added new internationalization keys for the global sync feature, including messages for syncing status and completion.
  • SparkyFitnessFrontend/src/App.tsx
    • Updated the global QueryClient configuration to reduce staleTime and enable refetchOnWindowFocus, refetchOnReconnect, and refetchOnMount for improved UI data freshness.
  • SparkyFitnessFrontend/src/components/GlobalSyncButton.tsx
    • Created a new React component for the "Sync All" button, which detects active providers and orchestrates the global sync process.
  • SparkyFitnessFrontend/src/hooks/Integrations/useIntegrations.ts
    • Introduced a useSyncInvalidation hook and integrated it into the onSuccess callbacks of various integration linking mutations (Fitbit, Withings, Strava, Polar) to ensure data invalidation upon successful linking.
  • SparkyFitnessFrontend/src/hooks/Integrations/useSyncAll.ts
    • Developed a new custom hook, useSyncAll, to encapsulate the logic for sequentially syncing data from multiple external providers and invalidating relevant queries.
  • SparkyFitnessFrontend/src/layouts/MainLayout.tsx
    • Integrated the GlobalSyncButton component into the application's main navigation header.
  • SparkyFitnessFrontend/src/pages/Settings/ExternalProviderSettings.tsx
    • Refactored manual sync functions for Withings, Garmin, Fitbit, Polar, Hevy, and Strava to utilize the new invalidateSyncData helper, ensuring comprehensive data refresh after individual syncs.
  • SparkyFitnessServer/integrations/fitbit/fitbitDataProcessor.js
    • Modified the Fitbit data processor to assign a default value of 0 to calories_burned if the activity data from Fitbit is missing this field, preventing database errors.
  • SparkyFitnessServer/integrations/hevy/hevyDataProcessor.js
    • Updated the Hevy data processor to explicitly set calories_burned to 0 for exercise entries, as Hevy typically does not provide this per-exercise.
  • SparkyFitnessServer/integrations/strava/stravaDataProcessor.js
    • Enhanced the Strava data processor to more robustly handle calories_burned by checking both summary and detailed activity data, defaulting to 0 if the value is absent.
  • SparkyFitnessServer/models/exerciseEntry.js
    • Adjusted the createExerciseEntry function to ensure calories_burned defaults to 0 if not provided, preventing NOT NULL constraint violations in the database.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new global synchronization feature, adding a GlobalSyncButton component to the main layout that allows users to manually sync data from active external providers like Strava, Fitbit, Polar, Withings, Garmin, and Hevy. New translation keys for sync-related messages have been added, and react-query settings were adjusted to reduce staleTime and enable refetching on window focus, reconnect, and mount for better responsiveness. A new useSyncAll hook was created to orchestrate the synchronization process, displaying toast notifications for success or failure. Additionally, the handling of calories_burned in exercise entries was improved across Fitbit, Hevy, and Strava data processors, ensuring a default value of 0 to prevent null issues. Review comments suggest refactoring the duplicated query invalidation logic into a shared hook, creating a shared constant for the list of manual sync providers, and updating the DataProvider interface to properly type the has_token property instead of using as unknown as.

@CodeWithCJ
Copy link
Owner Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a global sync feature and improves UI data freshness by adjusting react-query settings and centralizing invalidation logic. It also hardens backend data processing for Fitbit, Hevy, and Strava to prevent NOT NULL violations. The changes are well-structured, and the new useDiaryInvalidation hook and GlobalSyncButton component enhance maintainability and user experience. The updates to the backend data processors correctly handle missing values, which is a good improvement for data integrity.

@CodeWithCJ CodeWithCJ merged commit a52f7bd into main Feb 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant