@@ -308,13 +308,13 @@ struct BolusEntryView: View, HorizontalSizeClassOverride {
308308
309309 private var actionArea : some View {
310310 VStack ( spacing: 0 ) {
311- if isNoticeVisible {
311+ if viewModel . isNoticeVisible {
312312 warning ( for: viewModel. activeNotice!)
313313 . padding ( [ . top, . horizontal] )
314314 . transition ( AnyTransition . opacity. combined ( with: . move( edge: . bottom) ) )
315315 }
316316
317- if isManualGlucosePromptVisible {
317+ if viewModel . isManualGlucosePromptVisible {
318318 enterManualGlucoseButton
319319 . transition ( AnyTransition . opacity. combined ( with: . move( edge: . bottom) ) )
320320 }
@@ -325,20 +325,6 @@ struct BolusEntryView: View, HorizontalSizeClassOverride {
325325 . background ( Color ( . secondarySystemGroupedBackground) . shadow ( radius: 5 ) )
326326 }
327327
328- private var isNoticeVisible : Bool {
329- if viewModel. activeNotice == nil {
330- return false
331- } else if viewModel. activeNotice != . staleGlucoseData {
332- return true
333- } else {
334- return !viewModel. isManualGlucoseEntryEnabled
335- }
336- }
337-
338- private var isManualGlucosePromptVisible : Bool {
339- viewModel. activeNotice == . staleGlucoseData && !viewModel. isManualGlucoseEntryEnabled
340- }
341-
342328 private func warning( for notice: BolusEntryViewModel . Notice ) -> some View {
343329 switch notice {
344330 case . predictedGlucoseBelowSuspendThreshold( suspendThreshold: let suspendThreshold) :
@@ -354,19 +340,7 @@ struct BolusEntryView: View, HorizontalSizeClassOverride {
354340 )
355341 }
356342 }
357-
358- private var hasBolusEntryReadyToDeliver : Bool {
359- return self . viewModel. enteredBolus. doubleValue ( for: . internationalUnit( ) ) != 0
360- }
361-
362- enum ButtonChoice { case manualGlucoseEntry, actionButton }
363-
364- private var primaryButton : ButtonChoice {
365- if !isManualGlucosePromptVisible { return . actionButton }
366- if hasBolusEntryReadyToDeliver { return . actionButton }
367- return . manualGlucoseEntry
368- }
369-
343+
370344 private var enterManualGlucoseButton : some View {
371345 Button (
372346 action: {
@@ -376,43 +350,36 @@ struct BolusEntryView: View, HorizontalSizeClassOverride {
376350 } ,
377351 label: { Text ( " Enter Manual BG " , comment: " Button text prompting manual glucose entry on bolus screen " ) }
378352 )
379- . buttonStyle ( ActionButtonStyle ( primaryButton == . manualGlucoseEntry ? . primary : . secondary) )
353+ . buttonStyle ( ActionButtonStyle ( viewModel . primaryButton == . manualGlucoseEntry ? . primary : . secondary) )
380354 . padding ( [ . top, . horizontal] )
381355 }
382356
383357 private var actionButton : some View {
384- Button (
358+ Button < Text > (
385359 action: {
386- if ! self . hasBolusEntryReadyToDeliver {
360+ if self . viewModel . actionButtonAction == . enterBolus {
387361 self . shouldBolusEntryBecomeFirstResponder = true
388362 } else {
389363 self . viewModel. saveAndDeliver ( onSuccess: self . dismiss)
390364 }
391365 } ,
392366 label: {
393- if hasDataToSave {
394- if viewModel. enteredBolus. doubleValue ( for: . internationalUnit( ) ) == 0 {
395- Text ( " Save without Bolusing " , comment: " Button text to save carbs and/or manual glucose entry without a bolus " )
396- } else {
397- Text ( " Save and Deliver " , comment: " Button text to save carbs and/or manual glucose entry and deliver a bolus " )
398- }
399- } else {
400- if viewModel. enteredBolus. doubleValue ( for: . internationalUnit( ) ) == 0 {
401- Text ( " Enter Bolus " , comment: " Button text to begin entering a bolus " )
402- } else {
403- Text ( " Deliver " , comment: " Button text to deliver a bolus " )
404- }
367+ switch viewModel. actionButtonAction {
368+ case . saveWithoutBolusing:
369+ return Text ( " Save without Bolusing " , comment: " Button text to save carbs and/or manual glucose entry without a bolus " )
370+ case . saveAndDeliver:
371+ return Text ( " Save and Deliver " , comment: " Button text to save carbs and/or manual glucose entry and deliver a bolus " )
372+ case . enterBolus:
373+ return Text ( " Enter Bolus " , comment: " Button text to begin entering a bolus " )
374+ case . deliver:
375+ return Text ( " Deliver " , comment: " Button text to deliver a bolus " )
405376 }
406377 }
407378 )
408- . buttonStyle ( ActionButtonStyle ( primaryButton == . actionButton ? . primary : . secondary) )
379+ . buttonStyle ( ActionButtonStyle ( viewModel . primaryButton == . actionButton ? . primary : . secondary) )
409380 . padding ( )
410381 }
411382
412- private var hasDataToSave : Bool {
413- viewModel. enteredManualGlucose != nil || viewModel. potentialCarbEntry != nil
414- }
415-
416383 private func alert( for alert: BolusEntryViewModel . Alert ) -> SwiftUI . Alert {
417384 switch alert {
418385 case . recommendationChanged:
0 commit comments