CarbsInputView.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import Foundation
  2. import SwiftUI
  3. // MARK: - Carbs Input View
  4. struct CarbsInputView: View {
  5. @Environment(\.dismiss) var dismiss
  6. @State private var carbsAmount = 0
  7. @State private var navigateToBolus = false // Track navigation to BolusInputView
  8. let state: WatchState
  9. let continueToBolus: Bool
  10. var body: some View {
  11. let buttonLabel = continueToBolus ? "Proceed" : "Add Carbs"
  12. // TODO: introduce meal setting fpu enablement to conditional handle FPU
  13. VStack {
  14. Picker("Carbs", selection: $carbsAmount) {
  15. ForEach(0 ... 100, id: \.self) { amount in
  16. Text("\(amount)g").tag(amount)
  17. }
  18. }
  19. Button(buttonLabel) {
  20. if continueToBolus {
  21. state.carbsAmount = carbsAmount
  22. navigateToBolus = true
  23. } else {
  24. state.sendCarbsRequest(carbsAmount)
  25. dismiss()
  26. }
  27. }
  28. .buttonStyle(.bordered)
  29. .tint(.orange)
  30. }
  31. .navigationTitle("Add Carbs")
  32. .navigationDestination(isPresented: $navigateToBolus) {
  33. BolusInputView(state: state) // Navigate to BolusInputView
  34. }
  35. }
  36. }