Skip to content

Keep the carb detail sheet across remounts and share carb treatment construction - #758

Merged
bjorkert merged 3 commits into
touch-carbfrom
touch-carb-review-fixes
Sep 26, 2026
Merged

bjorkert merged 3 commits into
touch-carbfrom
touch-carb-review-fixes

Conversation

@bjorkert

Copy link
Copy Markdown
Member

Follow-up to #757 (double-tap on a carb mark opens its details). Targets the touch-carb branch.

  • Sheet closed on app re-activation. BGChartView remounts its chart subtree on didBecomeActive, which tore down the @State selection and its .sheet inside MainBGChart. BGChartView now owns selectedTreatment and the .sheet, outside the remounted subtree; MainBGChart writes the selection through a Binding. An open sheet survives Notification Center, Control Center and backgrounding, so in-progress edits and the commandTracker.consume(key:) path in TreatmentDetailView are kept.
  • Duplicated Treatment construction. Treatment.carb(nightscoutID:date:carbs:bgValue:trioMeal:loopCarb:) builds carb entries for both TreatmentsViewModel and CarbTreatment.detailTreatment, including the subtitle rules. nightscoutID on LoopCarbTreatment / TrioMealTreatment is optional, and the factory applies the single unknown-<date> id fallback.
  • Refresh on dismiss. The sheet's onDismiss refresh is gone. MainViewController observes .remoteMealCommandDidComplete and reschedules the .treatments task to now, so the chart follows a remote edit or delete whether it was sent from the chart sheet or the Treatments tab. View-only dismissals trigger no fetch.
  • Double-tap hit test. handleDoubleTap hit-tests model.carbs only, so a bolus/SMB drawn nearer than the (offset) carb dot cannot shadow it. The nearest carb mark wins; one without AID metadata falls through to the zoom preset.
  • Duplicated root-meal lookup. Treatment.rootMealsByFPUID(_:) and Treatment.rootMeal(in:) back both TreatmentsViewModel.rootMeal(forFPUChild:) and the chart sheet's root lookup.
  • Doc comment. MainBGChart: "Double-tap on a carb mark opens its details; elsewhere it cycles zoom presets."

Treatment.carb builds a carb entry for both the treatments list and the
chart's detail sheet, with one id fallback for entries without a
Nightscout _id. Treatment.rootMealsByFPUID and rootMeal(in:) back the
FPU-child root lookup in both places.
The chart's carb marks follow a remote meal edit or delete from any
screen by running the treatments task as soon as the command resolves.
BGChartView owns the selected carb and its sheet, outside the subtree
that is remounted on foregrounding, so an open sheet survives a trip to
Notification Center or the background. Double-tap hit-tests carb marks
only, so a nearby bolus cannot shadow the carb it sits next to.
@bjorkert
bjorkert merged commit 02dd910 into touch-carb Sep 26, 2026
1 check passed
@bjorkert
bjorkert deleted the touch-carb-review-fixes branch September 26, 2026 14:54
bjorkert added a commit that referenced this pull request Sep 26, 2026
* Add ability to double-click carbs to enter Treatments screen

* Keep the carb detail sheet across remounts and share carb treatment construction (#758)

* Share carb Treatment construction and root-meal lookup

Treatment.carb builds a carb entry for both the treatments list and the
chart's detail sheet, with one id fallback for entries without a
Nightscout _id. Treatment.rootMealsByFPUID and rootMeal(in:) back the
FPU-child root lookup in both places.

* Refresh treatments when a remote meal command completes

The chart's carb marks follow a remote meal edit or delete from any
screen by running the treatments task as soon as the command resolves.

* Keep the carb detail sheet in the chart shell

BGChartView owns the selected carb and its sheet, outside the subtree
that is remounted on foregrounding, so an open sheet survives a trip to
Notification Center or the background. Double-tap hit-tests carb marks
only, so a nearby bolus cannot shadow the carb it sits next to.

---------

Co-authored-by: Jonas Björkert <jonas@bjorkert.se>
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