DeactivatePodView.swift 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // DeactivatePodView.swift
  3. // OmniKit
  4. //
  5. // Created by Pete Schwamb on 3/9/20.
  6. // Copyright © 2021 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import LoopKitUI
  10. struct DeactivatePodView: View {
  11. @ObservedObject var viewModel: DeactivatePodViewModel
  12. @Environment(\.verticalSizeClass) var verticalSizeClass
  13. @Environment(\.guidanceColors) var guidanceColors
  14. @State private var removePodModalIsPresented: Bool = false
  15. var body: some View {
  16. GuidePage(content: {
  17. VStack {
  18. LeadingImage("Pod")
  19. HStack {
  20. Text(viewModel.instructionText)
  21. .fixedSize(horizontal: false, vertical: true)
  22. Spacer()
  23. }
  24. }
  25. .padding(.bottom, 8)
  26. }) {
  27. VStack {
  28. if viewModel.state.showProgressDetail {
  29. VStack {
  30. viewModel.error.map {ErrorView($0).accessibility(sortPriority: 0)}
  31. if viewModel.error == nil {
  32. VStack {
  33. ProgressIndicatorView(state: viewModel.state.progressState)
  34. if self.viewModel.state.isFinished {
  35. FrameworkLocalText("Deactivated", comment: "Label text showing pod is deactivated")
  36. .bold()
  37. .padding(.top)
  38. }
  39. }
  40. .padding(.bottom, 8)
  41. }
  42. }
  43. .transition(AnyTransition.opacity.combined(with: .move(edge: .bottom)))
  44. }
  45. if viewModel.error != nil {
  46. Button(action: {
  47. if viewModel.podAttachedToBody {
  48. removePodModalIsPresented = true
  49. } else {
  50. viewModel.discardPod()
  51. }
  52. }) {
  53. FrameworkLocalText("Discard Pod", comment: "Text for discard pod button")
  54. .accessibility(identifier: "button_discard_pod_action")
  55. .actionButtonStyle(.destructive)
  56. }
  57. .disabled(viewModel.state.isProcessing)
  58. }
  59. Button(action: {
  60. viewModel.continueButtonTapped()
  61. }) {
  62. Text(viewModel.state.actionButtonDescription)
  63. .accessibility(identifier: "button_next_action")
  64. .accessibility(label: Text(viewModel.state.actionButtonAccessibilityLabel))
  65. .actionButtonStyle(viewModel.state.actionButtonStyle)
  66. }
  67. .disabled(viewModel.state.isProcessing)
  68. }
  69. .padding()
  70. }
  71. .alert(isPresented: $removePodModalIsPresented) { removePodModal }
  72. .navigationBarTitle("Deactivate Pod", displayMode: .automatic)
  73. .navigationBarItems(trailing:
  74. Button("Cancel") {
  75. viewModel.didCancel?()
  76. }
  77. )
  78. }
  79. var removePodModal: Alert {
  80. return Alert(
  81. title: FrameworkLocalText("Remove Pod from Body", comment: "Title for remove pod modal"),
  82. message: FrameworkLocalText("Your Pod may still be delivering Insulin.\nRemove it from your body, then tap “Continue.“", comment: "Alert message body for confirm pod attachment"),
  83. primaryButton: .cancel(),
  84. secondaryButton: .default(FrameworkLocalText("Continue", comment: "Title of button to continue discard"), action: { viewModel.discardPod() })
  85. )
  86. }
  87. }