fix: completed tasks reappearing as overdue (#2) #4

Merged
admin merged 1 commits from fix/issue-2-task-completion-persistence into master 2026-04-12 10:14:26 -05:00
Owner

Summary

  • Fixed care tasks reappearing as incomplete/overdue after marking them complete and navigating away
  • Root cause: PlantDetailView only used .task (runs once on first appearance) to load schedule data, missing updates from Core Data background context saves
  • Added .onAppear to reload the care schedule every time the view appears, matching the pattern already used in TodayView

Files Changed

  • PlantGuide/Presentation/Scenes/PlantDetail/PlantDetailViewModel.swift — Added refreshSchedule() public method to reload schedule from Core Data
  • PlantGuide/Presentation/Scenes/PlantDetail/PlantDetailView.swift — Added .onAppear handler to refresh schedule on every view appearance

How to Test

  1. Navigate to a plant in the collection that has care tasks
  2. Mark a task as complete (tap the circle button)
  3. Verify the task disappears
  4. Navigate back to the collection list
  5. Tap the same plant again
  6. Verify the completed task does NOT reappear in the upcoming tasks section

Fixes #2

## Summary - Fixed care tasks reappearing as incomplete/overdue after marking them complete and navigating away - Root cause: PlantDetailView only used `.task` (runs once on first appearance) to load schedule data, missing updates from Core Data background context saves - Added `.onAppear` to reload the care schedule every time the view appears, matching the pattern already used in TodayView ## Files Changed - `PlantGuide/Presentation/Scenes/PlantDetail/PlantDetailViewModel.swift` — Added `refreshSchedule()` public method to reload schedule from Core Data - `PlantGuide/Presentation/Scenes/PlantDetail/PlantDetailView.swift` — Added `.onAppear` handler to refresh schedule on every view appearance ## How to Test 1. Navigate to a plant in the collection that has care tasks 2. Mark a task as complete (tap the circle button) 3. Verify the task disappears 4. Navigate back to the collection list 5. Tap the same plant again 6. Verify the completed task does NOT reappear in the upcoming tasks section Fixes #2
admin added 1 commit 2026-04-12 10:13:21 -05:00
When a user marked a care task as complete, the task would disappear
from the upcoming tasks section. However, upon navigating away and
returning to the plant detail, the task would reappear as incomplete
and overdue.

The root cause was that PlantDetailView only used .task to load
schedule data, which runs once on first appearance. When the view was
recreated (e.g., after navigating back from the collection list), the
Core Data fetch could return stale data due to context isolation in
NSPersistentCloudKitContainer.

Added .onAppear to reload the care schedule from Core Data every time
the view appears, matching the pattern already used in TodayView.
Also exposed a refreshSchedule() method on the ViewModel for this
purpose.

Fixes #2

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
admin merged commit 98244b3d65 into master 2026-04-12 10:14:26 -05:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/PlantGuide#4