ManualTempBasalStateModel.swift 787 B

1234567891011121314151617181920212223242526272829
  1. import SwiftUI
  2. extension ManualTempBasal {
  3. final class StateModel: BaseStateModel<Provider> {
  4. @Injected() var apsManager: APSManager!
  5. @Published var rate: Decimal = 0
  6. @Published var durationIndex = 0
  7. let durationValues = stride(from: 30.0, to: 720.1, by: 30.0).map { $0 }
  8. override func subscribe() {}
  9. func cancel() {
  10. Task {
  11. await apsManager.enactTempBasal(rate: 0, duration: 0)
  12. showModal(for: nil)
  13. }
  14. }
  15. func enact() {
  16. Task {
  17. let duration = durationValues[durationIndex]
  18. await apsManager.enactTempBasal(rate: Double(rate), duration: duration * 60)
  19. showModal(for: nil)
  20. }
  21. }
  22. }
  23. }