Skip to content

Mobile App Edit Food Screens#836

Merged
CodeWithCJ merged 7 commits intoCodeWithCJ:mainfrom
apedley:app-edit-food
Mar 4, 2026
Merged

Mobile App Edit Food Screens#836
CodeWithCJ merged 7 commits intoCodeWithCJ:mainfrom
apedley:app-edit-food

Conversation

@apedley
Copy link
Contributor

@apedley apedley commented Mar 4, 2026

Tip

Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run pnpm run validate to check for any errors.
PRs that include tests and clear screenshots are highly preferred!

Description

Related Issue

PR type [X] Issue [X] New Feature [ ] Documentation
Linked Issue: #

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

Screenshots (if applicable)

Before

[Insert screenshot/GIF here]

After

[Insert screenshot/GIF here]

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 mobile application's food tracking capabilities by introducing the ability to edit existing food entries. Users can now adjust various aspects of their logged food, from basic quantity and meal type to detailed nutritional information. This feature required substantial updates across the mobile UI, new API endpoints, and a refactoring of how food entry data is handled on the server, all while maintaining compatibility with existing web and server functionalities. Additionally, it includes important updates to health data synchronization mappings for improved accuracy.

Highlights

  • Mobile App Food Entry Editing: Implemented comprehensive functionality to edit existing food entries directly within the mobile application, allowing users to modify quantity, serving details, meal type, date, and even individual nutritional values.
  • Refactored Food Form Screen: The ManualFoodEntryScreen was renamed to FoodFormScreen and refactored to support multiple modes, enabling its reuse for both creating new food entries and adjusting nutrition details of existing ones.
  • Server-Side API Enhancements: Introduced a new updateFoodEntry API endpoint and updated existing snapshot logic to handle partial updates and inline nutrition overrides for food entries, ensuring data consistency across the platform.
  • Health Data Mapping Updates: Corrected and expanded the mapping of exercise names for both Health Connect (Android) and HealthKit (iOS) integrations, improving the accuracy of synchronized health data.
  • Centralized Query Test Utilities: Created a new utility file to centralize react-query test client and wrapper creation, significantly reducing boilerplate and improving consistency across hook tests.
Changelog
  • SparkyFitnessMobile/App.tsx
    • Renamed ManualFoodEntryScreen to FoodFormScreen and updated its usage in the navigation stack.
  • SparkyFitnessMobile/tests/hooks/queryTestUtils.ts
    • Added a new utility file to centralize react-query test client and wrapper creation.
  • SparkyFitnessMobile/tests/hooks/useDailySummary.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useDeleteFoodEntry.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useExternalFoodSearch.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useExternalProviders.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useFoodSearch.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useFoods.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useMeasurements.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useMeasurementsRange.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/usePreferences.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useProfile.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useServerConnection.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useSyncHealthData.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/hooks/useUpdateFoodEntry.test.ts
    • Added new tests for the useUpdateFoodEntry hook, covering success, error handling, and cache invalidation.
  • SparkyFitnessMobile/tests/hooks/useWaterIntakeMutation.test.ts
    • Refactored tests to use the new createTestQueryClient and createQueryWrapper utilities.
  • SparkyFitnessMobile/tests/services/healthconnect/dataTransformation.test.ts
    • Updated exercise type codes and names in tests to reflect new Health Connect mappings.
  • SparkyFitnessMobile/tests/services/profileApi.test.ts
    • Updated API endpoint path from /api/auth/profiles to /api/identity/profiles in tests.
  • SparkyFitnessMobile/package.json
    • Added testPathIgnorePatterns to Jest configuration to exclude the new queryTestUtils.ts from direct test execution.
  • SparkyFitnessMobile/src/components/FoodForm.tsx
    • Reordered serving unit options for better user experience.
    • Updated a useEffect dependency array to include onServingChange.
  • SparkyFitnessMobile/src/components/Icon.tsx
    • Added a new 'pencil' icon mapping for editing functionality.
  • SparkyFitnessMobile/src/hooks/index.ts
    • Exported the new useUpdateFoodEntry hook.
  • SparkyFitnessMobile/src/hooks/useUpdateFoodEntry.ts
    • Added a new hook useUpdateFoodEntry for handling food entry updates, including API calls, success/error handling, and cache invalidation.
  • SparkyFitnessMobile/src/screens/FoodEntryAddScreen.tsx
    • Modified to support adjusting nutrition values for food entries via a new FoodForm screen.
    • Updated payload construction and UI elements to reflect potential nutrition adjustments.
  • SparkyFitnessMobile/src/screens/FoodEntryViewScreen.tsx
    • Implemented comprehensive food entry editing functionality, including quantity adjustment, variant selection, date/meal type changes, and nutrition overrides.
    • Added animated transitions for editing mode UI changes.
    • Integrated useUpdateFoodEntry hook for saving changes.
  • SparkyFitnessMobile/src/screens/FoodFormScreen.tsx
    • Renamed ManualFoodEntryScreen to FoodFormScreen.
    • Refactored the screen to support two modes: 'create-food' and 'adjust-entry-nutrition', allowing it to be reused for editing existing entries.
  • SparkyFitnessMobile/src/screens/FoodScanScreen.tsx
    • Updated navigation calls to use the new FoodForm screen with the 'create-food' mode.
  • SparkyFitnessMobile/src/screens/FoodSearchScreen.tsx
    • Updated navigation call to use the new FoodForm screen with the 'create-food' mode.
  • SparkyFitnessMobile/src/services/api/foodEntriesApi.ts
    • Added a new updateFoodEntry API function and its corresponding UpdateFoodEntryPayload interface.
  • SparkyFitnessMobile/src/services/api/foodsApi.ts
    • Added a blank line for formatting.
  • SparkyFitnessMobile/src/services/api/profileApi.ts
    • Updated the API endpoint for fetching user profiles from /api/auth/profiles to /api/identity/profiles.
  • SparkyFitnessMobile/src/services/healthconnect/dataTransformation.ts
    • Updated the EXERCISE_MAP with a more comprehensive list of exercise types and their corresponding Health Connect IDs.
  • SparkyFitnessMobile/src/services/healthkit/dataTransformation.ts
    • Updated the ACTIVITY_MAP with a more comprehensive list of HealthKit workout activity types.
  • SparkyFitnessMobile/src/types/foodEntries.ts
    • Added user_id and meal_type_id fields to the FoodEntry interface.
  • SparkyFitnessMobile/src/types/navigation.ts
    • Updated RootStackParamList to reflect the renaming of ManualFoodEntry to FoodForm.
    • Added new parameters for FoodEntryAdd, FoodEntryView, and FoodForm to support nutrition adjustments and screen navigation.
  • SparkyFitnessServer/models/food.js
    • Removed the updateFoodEntriesSnapshot function and its export, as its logic was moved or refactored.
  • SparkyFitnessServer/models/foodEntry.js
    • Modified createFoodEntry to apply inline nutrition overrides from client data to the food snapshot.
    • Updated the getFoodEntriesByDate query to include user_id and meal_type_id.
  • SparkyFitnessServer/models/foodMisc.js
    • Removed updated_at from the updateFoodEntriesSnapshot SQL query.
  • SparkyFitnessServer/models/foodRepository.js
    • Removed updateFoodEntriesSnapshot from the exports.
  • SparkyFitnessServer/routes/foodCrudRoutes.js
    • Modified the /update-snapshot route to only require foodId (making variantId optional) and updated the error message.
  • SparkyFitnessServer/services/foodCoreService.js
    • Refactored updateFoodEntriesSnapshot to handle updates for a single variant or all variants of a food.
    • Introduced a new helper function updateSnapshotForVariant.
  • SparkyFitnessServer/services/foodEntryService.js
    • Refactored updateFoodEntry to conditionally rebuild the food snapshot based on variant changes or apply inline nutrition overrides.
    • Ensured meal_type_id is correctly handled during updates.
  • SparkyFitnessServer/tests/foodCoreService.updateSnapshot.test.js
    • Added new tests for foodCoreService.updateFoodEntriesSnapshot, covering single and multiple variant updates, error handling, and snapshot data integrity.
  • SparkyFitnessServer/tests/foodEntrySnapshot.test.js
    • Added new tests for foodRepository snapshot-related functions, specifically updateFoodEntriesSnapshot, clearUserIgnoredUpdate, and getFoodsNeedingReview.
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 the ability to edit food entries in the mobile app, a significant feature enhancement. This includes a new FoodFormScreen for adjusting nutrition details, which is used both for creating new manual entries and for editing existing ones. The FoodEntryViewScreen has been extensively refactored to support a new edit mode with animated UI transitions. On the server side, the food entry update logic has been enhanced to handle custom nutrition snapshots. Additionally, the PR includes a valuable refactoring of react-query test setup, improving test code clarity and maintainability across numerous files.

My review identifies a couple of minor UI state management issues in the new editing flow on the FoodEntryViewScreen where unsaved changes are not consistently reflected in the UI or when re-opening the edit form. The rest of the implementation, including the backend changes and new tests, appears solid.

@CodeWithCJ CodeWithCJ merged commit 547ad71 into CodeWithCJ:main Mar 4, 2026
6 checks passed
@CodeWithCJ
Copy link
Owner

@apedley Is it been reviewed with web as well as it involves server side code change?

@apedley
Copy link
Contributor Author

apedley commented Mar 5, 2026

@apedley Is it been reviewed with web as well as it involves server side code change?

Yes I only added new options to the current server routes (and one new route.) Also verified that editing food works just like before on web.

@apedley apedley deleted the app-edit-food branch March 5, 2026 18:21
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.

[Bug]: Health Connect indoor rowing session comes through as 'Exercise Type 54'

2 participants