Back to Blocks
PXL-730Running
Medium

๐Ÿณ View and edit your recipes

Labels
1-circerecipesmeal loggingui/uxFeature

What we're building:

Right now, when you create a recipe in NutriKit, you can save it with all the ingredients and amounts. However, once saved, you can't view the ingredient list anymore, and there's no way to edit the recipe if you need to make changes. This task fixes both issues by making recipes display their complete ingredient breakdown when you tap on them, and adding an edit button so you can modify recipes just like any other food in your database.


Problem Statement

Recipes are not loading/displaying correctly in the FoodDetailsView, and there is currently no ability to edit recipes once they are created. This impacts users who have created recipes and need to modify them or view their ingredient details.

Technical Context

The FoodDetailsView (/Users/pxlshpr/Developer/NutriKit/NutriKit/Views/FoodDetailsView.swift) currently has an ingredientsSection that conditionally displays when food.type == .recipe and when !food.childrenFoodItems.isEmpty (lines 262-273). The section is supposed to show recipe ingredients by iterating through food.childrenFoodItems, displaying each ingredient with its emoji, name, amount, and calorie information.

The Food model has a childrenFoodItems: [FoodItem] property that stores recipe ingredients. This is populated during food creation/editing but may not be loading correctly when displaying existing recipes in the details view.

Tasks Required

1. Debug Recipe Loading Issue

  • โ—Investigate why food.childrenFoodItems is empty or not populating when viewing existing recipes
  • โ—Check data persistence layer to ensure recipe ingredients are being saved correctly to CloudKit/Core Data
  • โ—Verify the Food entity mapping includes proper handling of the childrenFoodItems relationship
  • โ—Add logging or breakpoints to trace where the recipe ingredients are being lost in the data flow
  • โ—Test with known recipe foods to confirm whether the issue is in saving, loading, or both

2. Implement Recipe Editing Functionality

  • โ—Add an "Edit" button to the FoodDetailsView toolbar when food.type == .recipe
  • โ—Create navigation to the FoodForm with editing mode enabled for recipes
  • โ—Ensure the FoodForm properly loads existing recipe ingredients into the editing interface
  • โ—Verify that editing a recipe updates both the recipe metadata and its childrenFoodItems correctly
  • โ—Ensure edited recipes save properly and the changes persist across app restarts
  • โ—Add proper validation to prevent breaking existing recipe data during edits

Acceptance Criteria

  • โ— Existing recipes display their complete ingredient list in the FoodDetailsView
  • โ— Each ingredient shows: emoji, name, amount (with proper units), and calorie contribution
  • โ— An "Edit" button appears in the toolbar when viewing a recipe
  • โ— Tapping "Edit" opens the FoodForm in edit mode with all recipe data pre-populated
  • โ— Modifying recipe ingredients (add/remove/edit amounts) saves correctly
  • โ— After editing and saving, the FoodDetailsView reflects the updated recipe information
  • โ— Recipe edits persist across app restarts and sync properly via CloudKit

Files to Review

  • โ—/Users/pxlshpr/Developer/NutriKit/NutriKit/Views/FoodDetailsView.swift - Main view displaying food details
  • โ—/Users/pxlshpr/Developer/NutriKit/Packages/FoodCore/Sources/FoodCore/Structs/Food/Food.swift - Food model definition
  • โ—/Users/pxlshpr/Developer/NutriKit/NutriKit/Refactor Inbox/FoodsUI/Screens/FoodForm/FoodForm.swift - Food editing interface
  • โ—/Users/pxlshpr/Developer/NutriKit/Packages/App/Sources/App/NSManagedObjects/FoodEntity.swift - Core Data entity
  • โ—/Users/pxlshpr/Developer/NutriKit/Packages/App/Sources/App/Extensions/CKRecord.swift - CloudKit persistence

Additional Notes

The ingredientRow function in FoodDetailsView is already implemented to display ingredients nicely, so the UI layer is ready. The issue appears to be in the data loading/persistence layer. Recipe editing should follow the same patterns used for editing regular foods, but with special attention to the childrenFoodItems relationship.

Build instruction: Use -destination 'platform=iOS Simulator,name=iPhone 17 Pro' when building this project

Created Dec 12, 2025, 8:47 PM ยท Updated Jan 6, 2026, 1:07 PM