Просмотр исходного кода

Fix popup after @polscm32 refactor; cleanup

dnzxy 2 лет назад
Родитель
Сommit
d4ae53d9d5

+ 0 - 1
FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift

@@ -59,7 +59,6 @@ extension AddCarbs {
                 showModal(for: nil)
             } else if carbs > 0 {
                 saveToCoreData(carbsToStore)
-//                showModal(for: .bolus(waitForSuggestion: true, fetch: true))
             } else {
                 hideModal()
             }

+ 2 - 2
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -332,7 +332,7 @@ extension Bolus {
 //            }
 //        }
 
-        func addCarbs(_ continue_: Bool, fetch: Bool) {
+        func addCarbs() {
             guard carbs > 0 || fat > 0 || protein > 0 else { return }
             carbs = min(carbs, maxCarbs)
             id_ = UUID().uuidString
@@ -350,7 +350,7 @@ extension Bolus {
             )]
             carbsStorage.storeCarbs(carbsToStore)
 
-            if skipBolus, !continue_, !fetch {
+            if skipBolus {
                 apsManager.determineBasalSync()
                 showModal(for: nil)
             } else if carbs > 0 {

+ 29 - 89
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -7,9 +7,6 @@ extension Bolus {
     struct AlternativeBolusCalcRootView: BaseView {
         let resolver: Resolver
         let waitForSuggestion: Bool
-        let fetch: Bool
-        let editMode: Bool
-        let override: Bool
 
         @StateObject var state: StateModel
 
@@ -33,11 +30,6 @@ extension Bolus {
         @Environment(\.colorScheme) var colorScheme
 
         @FetchRequest(
-            entity: Meals.entity(),
-            sortDescriptors: [NSSortDescriptor(key: "createdAt", ascending: false)]
-        ) var meal: FetchedResults<Meals>
-
-        @FetchRequest(
             entity: Presets.entity(),
             sortDescriptors: [NSSortDescriptor(key: "dish", ascending: true)]
         ) var carbPresets: FetchedResults<Presets>
@@ -446,7 +438,7 @@ extension Bolus {
                         Button {
                             state.add()
                             state.hideModal()
-                            state.addCarbs(override, fetch: editMode)
+                            state.addCarbs()
                         }
                         label: { Text(exceededMaxBolus ? "Max Bolus exceeded!" : "Enact bolus") }
                             .frame(maxWidth: .infinity, alignment: .center)
@@ -459,7 +451,7 @@ extension Bolus {
                     Section {
                         Button {
                             state.hideModal()
-                            state.addCarbs(override, fetch: editMode)
+                            state.addCarbs()
                         }
                         label: { Text("Continue without bolus") }.frame(maxWidth: .infinity, alignment: .center)
                     }.listRowBackground(Color.chart)
@@ -488,7 +480,7 @@ extension Bolus {
                 .sheet(isPresented: $showInfo) {
                     calculationsDetailView
                         .presentationDetents(
-                            [fetch ? .large : .fraction(0.9), .large],
+                            [.fraction(0.9), .large],
                             selection: $calculatorDetent
                         )
                 }
@@ -839,49 +831,41 @@ extension Bolus {
 
                         DividerCustom()
 
-                        if fetch {
-                            // meal entries as grid rows
-
-                            GridRow {
-                                if let carbs = meal.first?.carbs, carbs > 0 {
-                                    Text("Carbs").foregroundColor(.secondary)
-                                    Color.clear.gridCellUnsizedAxes([.horizontal, .vertical])
-                                    HStack {
-                                        Text(carbs.formatted())
-                                        Text("g").foregroundColor(.secondary)
-                                    }.gridCellAnchor(.trailing)
-                                }
-                            }
-
+                        // meal entries as grid rows
+                        if state.carbs > 0 {
                             GridRow {
-                                if let fat = meal.first?.fat, fat > 0 {
-                                    Text("Fat").foregroundColor(.secondary)
-                                    Color.clear.gridCellUnsizedAxes([.horizontal, .vertical])
-                                    HStack {
-                                        Text(fat.formatted())
-                                        Text("g").foregroundColor(.secondary)
-                                    }.gridCellAnchor(.trailing)
-                                }
+                                Text("Carbs").foregroundColor(.secondary)
+                                Color.clear.gridCellUnsizedAxes([.horizontal, .vertical])
+                                HStack {
+                                    Text(state.carbs.formatted())
+                                    Text("g").foregroundColor(.secondary)
+                                }.gridCellAnchor(.trailing)
                             }
+                        }
 
+                        if state.fat > 0 {
                             GridRow {
-                                if let protein = meal.first?.protein, protein > 0 {
-                                    Text("Protein").foregroundColor(.secondary)
-                                    Color.clear.gridCellUnsizedAxes([.horizontal, .vertical])
-                                    HStack {
-                                        Text(protein.formatted())
-                                        Text("g").foregroundColor(.secondary)
-                                    }.gridCellAnchor(.trailing)
-                                }
+                                Text("Fat").foregroundColor(.secondary)
+                                Color.clear.gridCellUnsizedAxes([.horizontal, .vertical])
+                                HStack {
+                                    Text(state.fat.formatted())
+                                    Text("g").foregroundColor(.secondary)
+                                }.gridCellAnchor(.trailing)
                             }
+                        }
 
+                        if state.protein > 0 {
                             GridRow {
-                                if let note = meal.first?.note, note != "" {
-                                    Text("Note").foregroundColor(.secondary)
-                                    Text(note).foregroundColor(.secondary).gridCellColumns(2).gridCellAnchor(.trailing)
-                                }
+                                Text("Protein").foregroundColor(.secondary)
+                                Color.clear.gridCellUnsizedAxes([.horizontal, .vertical])
+                                HStack {
+                                    Text(state.protein.formatted())
+                                    Text("g").foregroundColor(.secondary)
+                                }.gridCellAnchor(.trailing)
                             }
+                        }
 
+                        if state.carbs > 0 || state.protein > 0 || state.fat > 0 {
                             DividerCustom()
                         }
 
@@ -942,50 +926,6 @@ extension Bolus {
         private var disabled: Bool {
             state.amount <= 0 || state.amount > state.maxBolus
         }
-
-        var changed: Bool {
-            ((meal.first?.carbs ?? 0) > 0) || ((meal.first?.fat ?? 0) > 0) || ((meal.first?.protein ?? 0) > 0)
-        }
-
-        var hasFatOrProtein: Bool {
-            ((meal.first?.fat ?? 0) > 0) || ((meal.first?.protein ?? 0) > 0)
-        }
-
-        var mealEntries: some View {
-            VStack {
-                if let carbs = meal.first?.carbs, carbs > 0 {
-                    HStack {
-                        Text("Carbs").foregroundColor(.secondary)
-                        Spacer()
-                        Text(carbs.formatted())
-                        Text("g").foregroundColor(.secondary)
-                    }
-                }
-                if let fat = meal.first?.fat, fat > 0 {
-                    HStack {
-                        Text("Fat").foregroundColor(.secondary)
-                        Spacer()
-                        Text(fat.formatted())
-                        Text("g").foregroundColor(.secondary)
-                    }
-                }
-                if let protein = meal.first?.protein, protein > 0 {
-                    HStack {
-                        Text("Protein").foregroundColor(.secondary)
-                        Spacer()
-                        Text(protein.formatted())
-                        Text("g").foregroundColor(.secondary)
-                    }
-                }
-                if let note = meal.first?.note, note != "" {
-                    HStack {
-                        Text("Note").foregroundColor(.secondary)
-                        Spacer()
-                        Text(note).foregroundColor(.secondary)
-                    }
-                }
-            }
-        }
     }
 
     struct DividerDouble: View {

+ 0 - 5
FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift

@@ -6,8 +6,6 @@ extension Bolus {
         let resolver: Resolver
         let waitForSuggestion: Bool
         let fetch: Bool
-        let editMode: Bool
-        let override: Bool
         @StateObject var state = StateModel()
 
         var body: some View {
@@ -16,9 +14,6 @@ extension Bolus {
                 AlternativeBolusCalcRootView(
                     resolver: resolver,
                     waitForSuggestion: waitForSuggestion,
-                    fetch: fetch,
-                    editMode: editMode,
-                    override: override,
                     state: state
                 )
             } else {

+ 0 - 4
FreeAPS/Sources/Modules/Home/HomeStateModel.swift

@@ -209,10 +209,6 @@ extension Home {
                 .store(in: &lifetime)
         }
 
-        func addCarbs() {
-            showModal(for: .addCarbs(editMode: false, override: false))
-        }
-
         func runLoop() {
             provider.heartbeatNow()
         }

+ 1 - 1
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -943,7 +943,7 @@ extension Home {
                     tabBarButton(index: 1, systemName: historySFSymbol, label: "History")
                     Spacer()
                     Button(action: {
-                        state.showModal(for: .bolus(waitForSuggestion: true, fetch: false, editMode: false, override: false))
+                        state.showModal(for: .bolus(waitForSuggestion: true, fetch: false))
                     }) {
                         Image(systemName: "plus.circle.fill")
                             .font(.system(size: 45))

+ 27 - 27
FreeAPS/Sources/Modules/OverrideProfilesConfig/View/OverrideProfilesRootView.swift

@@ -491,7 +491,7 @@ extension OverrideProfilesConfig {
                 high = high?.asMmolL
             }
             let isSelected = preset.id == selectedPresetID
-            
+
             return ZStack(alignment: .trailing, content: {
                 HStack {
                     VStack {
@@ -505,7 +505,7 @@ extension OverrideProfilesConfig {
                             )
                             .foregroundColor(.secondary)
                             .font(.caption)
-                            
+
                             Text(state.units.rawValue)
                                 .foregroundColor(.secondary)
                                 .font(.caption)
@@ -518,7 +518,7 @@ extension OverrideProfilesConfig {
                             Text("min")
                                 .foregroundColor(.secondary)
                                 .font(.caption)
-                            
+
                             Spacer()
                         }.padding(.top, 2)
                     }
@@ -527,31 +527,31 @@ extension OverrideProfilesConfig {
                         state.enactPreset(id: preset.id)
                         selectedPresetID = preset.id
                         showCheckmark.toggle()
-                        
-                        //deactivate showCheckmark after 3 seconds
+
+                        // deactivate showCheckmark after 3 seconds
                         DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
                             showCheckmark = false
                         }
                     }
-        
-                Image(systemName: "xmark.circle").foregroundColor(showCheckmark && isSelected ? Color.clear : Color.secondary)
-                    .contentShape(Rectangle())
-                    .padding(.vertical)
-                    .onTapGesture {
-                        removeAlert = Alert(
-                            title: Text("Are you sure?"),
-                            message: Text("Delete preset \"\(preset.displayName)\""),
-                            primaryButton: .destructive(Text("Delete"), action: { state.removePreset(id: preset.id) }),
-                            secondaryButton: .cancel()
-                        )
-                        isRemoveAlertPresented = true
-                    }
-                    .alert(isPresented: $isRemoveAlertPresented) {
-                        removeAlert!
-                    }
+
+                    Image(systemName: "xmark.circle").foregroundColor(showCheckmark && isSelected ? Color.clear : Color.secondary)
+                        .contentShape(Rectangle())
+                        .padding(.vertical)
+                        .onTapGesture {
+                            removeAlert = Alert(
+                                title: Text("Are you sure?"),
+                                message: Text("Delete preset \"\(preset.displayName)\""),
+                                primaryButton: .destructive(Text("Delete"), action: { state.removePreset(id: preset.id) }),
+                                secondaryButton: .cancel()
+                            )
+                            isRemoveAlertPresented = true
+                        }
+                        .alert(isPresented: $isRemoveAlertPresented) {
+                            removeAlert!
+                        }
                 }
                 if showCheckmark && isSelected {
-                    //show checkmark to indicate if the preset was actually pressed
+                    // show checkmark to indicate if the preset was actually pressed
                     Image(systemName: "checkmark.circle.fill")
                         .imageScale(.large)
                         .fontWeight(.bold)
@@ -613,14 +613,14 @@ extension OverrideProfilesConfig {
                             state.hideModal()
                             showCheckmark.toggle()
                             selectedPresetID = preset.id
-                            
-                            //deactivate showCheckmark after 3 seconds
+
+                            // deactivate showCheckmark after 3 seconds
                             DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
-                               showCheckmark = false
-                           }
+                                showCheckmark = false
+                            }
                         }
                     }
-                    //show checkmark to indicate if the preset was actually pressed
+                    // show checkmark to indicate if the preset was actually pressed
                     if showCheckmark && isSelected {
                         Image(systemName: "checkmark.circle.fill")
                             .imageScale(.large)

+ 3 - 8
FreeAPS/Sources/Router/Screen.swift

@@ -14,9 +14,8 @@ enum Screen: Identifiable, Hashable {
     case crEditor
     case targetsEditor
     case preferencesEditor
-    case addCarbs(editMode: Bool, override: Bool)
     case addTempTarget
-    case bolus(waitForSuggestion: Bool, fetch: Bool, editMode: Bool, override: Bool)
+    case bolus(waitForSuggestion: Bool, fetch: Bool)
     case manualTempBasal
     case autotuneConfig
     case dataTable
@@ -65,17 +64,13 @@ extension Screen {
             TargetsEditor.RootView(resolver: resolver)
         case .preferencesEditor:
             PreferencesEditor.RootView(resolver: resolver)
-        case let .addCarbs(editMode, override):
-            AddCarbs.RootView(resolver: resolver, editMode: editMode, override: override)
         case .addTempTarget:
             AddTempTarget.RootView(resolver: resolver)
-        case let .bolus(waitForSuggestion, fetch, editMode, override):
+        case let .bolus(waitForSuggestion, fetch):
             Bolus.RootView(
                 resolver: resolver,
                 waitForSuggestion: waitForSuggestion,
-                fetch: fetch,
-                editMode: editMode,
-                override: override
+                fetch: fetch
             )
         case .manualTempBasal:
             ManualTempBasal.RootView(resolver: resolver)