@@ -17,10 +17,12 @@ public struct SettingsView: View, HorizontalSizeClassOverride {
1717
1818 @ObservedObject var viewModel : SettingsViewModel
1919
20- @State var showPumpChooser : Bool = false
21- @State var showCGMChooser : Bool = false
22- @State var showServiceChooser : Bool = false
23- @State var showTherapySettings : Bool = false
20+ @State private var pumpChooserIsPresented : Bool = false
21+ @State private var cgmChooserIsPresented : Bool = false
22+ @State private var serviceChooserIsPresented : Bool = false
23+ @State private var therapySettingsIsPresented : Bool = false
24+ @State private var deletePumpDataAlertIsPresented = false
25+ @State private var deleteCGMDataAlertIsPresented = false
2426
2527 public init ( viewModel: SettingsViewModel ) {
2628 self . viewModel = viewModel
@@ -90,12 +92,12 @@ extension SettingsView {
9092
9193 private var therapySettingsSection : some View {
9294 Section ( header: SectionHeader ( label: NSLocalizedString ( " Configuration " , comment: " The title of the Configuration section in settings " ) ) ) {
93- LargeButton ( action: { self . showTherapySettings = true } ,
95+ LargeButton ( action: { self . therapySettingsIsPresented = true } ,
9496 includeArrow: false ,
9597 imageView: AnyView ( Image ( " Therapy Icon " ) ) ,
9698 label: NSLocalizedString ( " Therapy Settings " , comment: " Title text for button to Therapy Settings " ) ,
9799 descriptiveText: NSLocalizedString ( " Diabetes Treatment " , comment: " Descriptive text for Therapy Settings " ) )
98- . sheet ( isPresented: $showTherapySettings ) {
100+ . sheet ( isPresented: $therapySettingsIsPresented ) {
99101 TherapySettingsView (
100102 viewModel: TherapySettingsViewModel ( mode: . settings,
101103 therapySettings: self . viewModel. therapySettings,
@@ -126,12 +128,12 @@ extension SettingsView {
126128 label: viewModel. pumpManagerSettingsViewModel. name ( ) ,
127129 descriptiveText: NSLocalizedString ( " Insulin Pump " , comment: " Descriptive text for Insulin Pump " ) )
128130 } else {
129- LargeButton ( action: { self . showPumpChooser = true } ,
131+ LargeButton ( action: { self . pumpChooserIsPresented = true } ,
130132 includeArrow: false ,
131133 imageView: AnyView ( plusImage) ,
132134 label: NSLocalizedString ( " Add Pump " , comment: " Title text for button to add pump device " ) ,
133135 descriptiveText: NSLocalizedString ( " Tap here to set up a pump " , comment: " Descriptive text for button to add pump device " ) )
134- . actionSheet ( isPresented: $showPumpChooser ) {
136+ . actionSheet ( isPresented: $pumpChooserIsPresented ) {
135137 ActionSheet ( title: Text ( " Add Pump " , comment: " The title of the pump chooser in settings " ) , buttons: pumpChoices)
136138 }
137139 }
@@ -156,12 +158,12 @@ extension SettingsView {
156158 label: viewModel. cgmManagerSettingsViewModel. name ( ) ,
157159 descriptiveText: NSLocalizedString ( " Continuous Glucose Monitor " , comment: " Descriptive text for Continuous Glucose Monitor " ) )
158160 } else {
159- LargeButton ( action: { self . showCGMChooser = true } ,
161+ LargeButton ( action: { self . cgmChooserIsPresented = true } ,
160162 includeArrow: false ,
161163 imageView: AnyView ( plusImage) ,
162164 label: NSLocalizedString ( " Add CGM " , comment: " Title text for button to add CGM device " ) ,
163165 descriptiveText: NSLocalizedString ( " Tap here to set up a CGM " , comment: " Descriptive text for button to add CGM device " ) )
164- . actionSheet ( isPresented: $showCGMChooser ) {
166+ . actionSheet ( isPresented: $cgmChooserIsPresented ) {
165167 ActionSheet ( title: Text ( " Add CGM " , comment: " The title of the CGM chooser in settings " ) , buttons: cgmChoices)
166168 }
167169 }
@@ -187,12 +189,12 @@ extension SettingsView {
187189 descriptiveText: NSLocalizedString ( " Cloud Service " , comment: " The descriptive text for a services section item " ) )
188190 }
189191 if viewModel. servicesViewModel. inactiveServices ( ) . count > 0 {
190- LargeButton ( action: { self . showServiceChooser = true } ,
192+ LargeButton ( action: { self . serviceChooserIsPresented = true } ,
191193 includeArrow: false ,
192194 imageView: AnyView ( plusImage) ,
193195 label: NSLocalizedString ( " Add Service " , comment: " The title of the services section in settings " ) ,
194196 descriptiveText: NSLocalizedString ( " Tap here to set up a Service " , comment: " Descriptive text for button to add Service " ) )
195- . actionSheet ( isPresented: $showServiceChooser ) {
197+ . actionSheet ( isPresented: $serviceChooserIsPresented ) {
196198 ActionSheet ( title: Text ( " Add Service " , comment: " The title of the services action sheet in settings " ) , buttons: serviceChoices)
197199 }
198200 }
@@ -211,28 +213,41 @@ extension SettingsView {
211213
212214 private var deletePumpDataSection : some View {
213215 Section {
214- Button ( action: { self . viewModel . pumpManagerSettingsViewModel . deleteData ? ( ) } ) {
216+ Button ( action: { self . deletePumpDataAlertIsPresented . toggle ( ) } ) {
215217 HStack {
216218 Spacer ( )
217- Text ( " Delete Pump Data " ) . accentColor ( . destructive)
219+ Text ( " Delete Testing Pump Data " ) . accentColor ( . destructive)
218220 Spacer ( )
219221 }
220222 }
223+ . alert ( isPresented: $deletePumpDataAlertIsPresented) {
224+ makeDeleteAlert ( for: self . viewModel. pumpManagerSettingsViewModel)
225+ }
221226 }
222227 }
223228
224229 private var deleteCgmDataSection : some View {
225230 Section {
226- Button ( action: { self . viewModel . cgmManagerSettingsViewModel . deleteData ? ( ) } ) {
231+ Button ( action: { self . deleteCGMDataAlertIsPresented . toggle ( ) } ) {
227232 HStack {
228233 Spacer ( )
229- Text ( " Delete CGM Data " ) . accentColor ( . destructive)
234+ Text ( " Delete Testing CGM Data " ) . accentColor ( . destructive)
230235 Spacer ( )
231236 }
232237 }
238+ . alert ( isPresented: $deleteCGMDataAlertIsPresented) {
239+ makeDeleteAlert ( for: self . viewModel. cgmManagerSettingsViewModel)
240+ }
233241 }
234242 }
235243
244+ private func makeDeleteAlert( for model: DeviceViewModel ) -> SwiftUI . Alert {
245+ return SwiftUI . Alert ( title: Text ( " Delete Testing Data " ) ,
246+ message: Text ( " Are you sure you want to delete all your \( model. name ( ) ) Data? \n (This action is not reversible) " ) ,
247+ primaryButton: . cancel( ) ,
248+ secondaryButton: . destructive( Text ( " Delete " ) , action: model. deleteData) )
249+ }
250+
236251 private var supportSection : some View {
237252 Section ( header: SectionHeader ( label: NSLocalizedString ( " Support " , comment: " The title of the support section in settings " ) ) ) {
238253 NavigationLink ( destination: SupportScreenView ( didTapIssueReport: viewModel. didTapIssueReport) ) {
0 commit comments