Pārlūkot izejas kodu

Merge pull request #16 from dnzxy/tabbar

Fix popup after @polscm32 refactor; cleanup
polscm32 2 gadi atpakaļ
vecāks
revīzija
1d88ff7ffc

+ 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()
             }

+ 68 - 67
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -30,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>
@@ -613,7 +608,7 @@ extension Bolus {
 
                 let iobFormatted = self.insulinRounder(state.iob).formatted()
                 HStack {
-                    Text((state.iob != 0 ? "-" : "") + (state.iob >= 0 ? iobFormatted : "(" + iobFormatted + ")"))
+                    Text((state.iob >= 0 ? "-" : "") + (state.iob >= 0 ? iobFormatted : "(" + iobFormatted + ")"))
                     Text("U").foregroundColor(.secondary)
                 }.fontWeight(.bold)
                     .gridColumnAlignment(.trailing)
@@ -785,7 +780,7 @@ extension Bolus {
                 HStack {
                     Text(self.insulinRounder(state.insulinCalculated).formatted())
                         .fontWeight(.bold)
-                        .foregroundColor(.blue)
+                        .foregroundColor(state.wholeCalc >= state.maxBolus ? Color.loopRed : Color.blue)
                     Text("U").foregroundColor(.secondary)
                 }
                 .gridColumnAlignment(.trailing)
@@ -796,25 +791,37 @@ extension Bolus {
         var calcResultFormulaRow: some View {
             GridRow(alignment: .bottom) {
                 if state.useFattyMealCorrectionFactor {
-                    Text("Factor x Fatty Meal Factor x Full Bolus")
-                        .foregroundColor(.secondary.opacity(colorScheme == .dark ? 0.65 : 0.8))
-                        .font(.caption)
-                        .gridCellAnchor(.center)
-                        .gridCellColumns(3)
+                    Group {
+                        Text("Factor x Fatty Meal Factor x Full Bolus")
+                            .foregroundColor(.secondary.opacity(colorScheme == .dark ? 0.65 : 0.8))
+                            +
+                            Text(state.wholeCalc > state.maxBolus ? " ≈ Max Bolus" : "").foregroundColor(Color.loopRed)
+                    }
+                    .font(.caption)
+                    .gridCellAnchor(.center)
+                    .gridCellColumns(3)
                 } else if state.useSuperBolus {
-                    Text("(Factor x Full Bolus) + Super Bolus")
-                        .foregroundColor(.secondary.opacity(colorScheme == .dark ? 0.65 : 0.8))
-                        .font(.caption)
-                        .gridCellAnchor(.center)
-                        .gridCellColumns(3)
+                    Group {
+                        Text("(Factor x Full Bolus) + Super Bolus")
+                            .foregroundColor(.secondary.opacity(colorScheme == .dark ? 0.65 : 0.8))
+                            +
+                            Text(state.wholeCalc > state.maxBolus ? " ≈ Max Bolus" : "").foregroundColor(Color.loopRed)
+                    }
+                    .font(.caption)
+                    .gridCellAnchor(.center)
+                    .gridCellColumns(3)
                 } else {
                     Color.clear.gridCellUnsizedAxes([.horizontal, .vertical])
-                    Text("Factor x Full Bolus")
-                        .foregroundColor(.secondary.opacity(colorScheme == .dark ? 0.65 : 0.8))
-                        .font(.caption)
-                        .padding(.top, 5)
-                        .gridCellAnchor(.leading)
-                        .gridCellColumns(2)
+                    Group {
+                        Text("Factor x Full Bolus")
+                            .foregroundColor(.secondary.opacity(colorScheme == .dark ? 0.65 : 0.8))
+                            +
+                            Text(state.wholeCalc > state.maxBolus ? " ≈ Max Bolus" : "").foregroundColor(Color.loopRed)
+                    }
+                    .font(.caption)
+                    .padding(.top, 5)
+                    .gridCellAnchor(.leading)
+                    .gridCellColumns(2)
                 }
             }
         }
@@ -832,6 +839,44 @@ extension Bolus {
 
                         DividerCustom()
 
+                        // meal entries as grid rows
+                        if state.carbs > 0 {
+                            GridRow {
+                                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 {
+                                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 {
+                                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()
+                        }
+
                         GridRow {
                             Text("Detailed Calculation Steps").gridCellColumns(3).gridCellAnchor(.center)
                                 .padding(.bottom, 10)
@@ -889,50 +934,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 - 2
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 {

+ 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)