fix: Save to Collection button not responding (#1) #3

Merged
admin merged 1 commits from fix/issue-1-save-to-collection into master 2026-04-12 10:14:15 -05:00
Owner

Summary

  • Fixed the "Save to Collection" button on the identification screen remaining disabled after plant identification completes
  • Root cause: @Observable + @State tracking issue where computed properties in SwiftUI view modifiers don't reliably trigger re-renders
  • Replaced the empty .onChange workaround with a local @State property (saveEnabled) updated explicitly when selectedPrediction or saveState changes

Files Changed

  • PlantGuide/Presentation/Scenes/Identification/IdentificationView.swift — Added saveEnabled state, wired .onChange handlers, replaced viewModel.canSaveToCollection in button modifiers

How to Test

  1. Open app → Camera tab → Take a photo of a plant
  2. Wait for identification to complete
  3. Without tapping any prediction row, tap "Save to Collection"
  4. Verify the button is enabled (green) and the save succeeds with the "Plant Saved!" alert

Fixes #1

## Summary - Fixed the "Save to Collection" button on the identification screen remaining disabled after plant identification completes - Root cause: `@Observable` + `@State` tracking issue where computed properties in SwiftUI view modifiers don't reliably trigger re-renders - Replaced the empty `.onChange` workaround with a local `@State` property (`saveEnabled`) updated explicitly when `selectedPrediction` or `saveState` changes ## Files Changed - `PlantGuide/Presentation/Scenes/Identification/IdentificationView.swift` — Added `saveEnabled` state, wired `.onChange` handlers, replaced `viewModel.canSaveToCollection` in button modifiers ## How to Test 1. Open app → Camera tab → Take a photo of a plant 2. Wait for identification to complete 3. **Without tapping any prediction row**, tap "Save to Collection" 4. Verify the button is enabled (green) and the save succeeds with the "Plant Saved!" alert Fixes #1
admin added 1 commit 2026-04-12 10:09:41 -05:00
The Save to Collection button on the identification screen would remain
disabled after plant identification completed, requiring the user to tap
a prediction row before it would enable. This was caused by an @Observable
+ @State tracking issue where computed properties in SwiftUI view modifiers
don't always trigger re-renders when the underlying observable changes.

Replaced the empty .onChange workaround with a local @State property
(saveEnabled) that is explicitly updated when selectedPrediction or
saveState changes, ensuring the button state always reflects the current
ViewModel state.

Fixes #1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
admin merged commit 42084b6601 into master 2026-04-12 10:14:15 -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#3