ソースを参照

add custom progress view to home view when cancelling a bolus, otherwise the user could end up with too much iob when opening the calc again before the next loop

polscm32 2 年 前
コミット
28edd67728

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

@@ -72,6 +72,8 @@ extension Home {
 
         @Published var selectedTab: Int = 0
 
+        @Published var waitForSuggestion: Bool = false
+
         let coredataContext = CoreDataStack.shared.persistentContainer.viewContext
 
         override func subscribe() {
@@ -215,6 +217,9 @@ extension Home {
 
         func cancelBolus() {
             apsManager.cancelBolus()
+
+            // perform determine basal sync, otherwise you have could end up with too much iob when opening the calculator again
+            apsManager.determineBasalSync()
         }
 
         func cancelProfile() {
@@ -438,6 +443,7 @@ extension Home.StateModel:
         self.suggestion = suggestion
         carbsRequired = suggestion.carbsReq
         setStatusTitle()
+        waitForSuggestion = false
     }
 
     func settingsDidChange(_ settings: FreeAPSSettings) {

+ 12 - 75
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -690,7 +690,10 @@ extension Home {
                     Spacer()
 
                     Button {
-                        state.cancelBolus()
+                        Task {
+                            state.waitForSuggestion = true
+                            state.cancelBolus()
+                        }
                     } label: {
                         Image(systemName: "xmark.app")
                             .font(.system(size: 25))
@@ -787,77 +790,6 @@ extension Home {
             }
         }
 
-//
-//        @ViewBuilder func tabBarButton(index: Int, systemName: String, label: String) -> some View {
-//            Button(action: {
-//                selectedTab = index
-//            }) {
-//                ZStack(alignment: .bottom, content: {
-//                    VStack {
-//                        Image(systemName: systemName)
-//                            .font(.system(size: 22))
-//                            .foregroundStyle(selectedTab == index ? Color(.label) : Color.gray)
-//                        Text(label)
-//                            .font(.caption2)
-//                            .foregroundStyle(selectedTab == index ? Color(.label) : Color.gray)
-//                            .padding(.top, 1)
-//                    }
-//                    if selectedTab == index {
-//                        Capsule()
-//                            .frame(width: 25, height: 5)
-//                            .foregroundStyle(Color(.label))
-//                            .offset(y: 10)
-//                    }
-//                })
-//            }
-//        }
-//
-//        @ViewBuilder func customTabBar() -> some View {
-//            VStack {
-//                ZStack {
-//                    switch selectedTab {
-//                    case 0:
-//                        mainView()
-//                    case 1:
-//                        NavigationStack { DataTable.RootView(resolver: resolver) }
-//                    case 2:
-//                        NavigationStack { OverrideProfilesConfig.RootView(resolver: resolver) }
-//                    case 3:
-//                        NavigationStack { Settings.RootView(resolver: resolver) }
-//                    default:
-//                        mainView()
-//                    }
-//                }
-//                HStack {
-//                    tabBarButton(
-//                        index: 0,
-//                        systemName: selectedTab == 0 ? "house.fill" : "house",
-//                        label: "Home"
-//                    )
-//                    Spacer()
-//                    tabBarButton(index: 1, systemName: historySFSymbol, label: "History")
-//                    Spacer()
-//                    Button(action: {
-//                        state.showModal(for: .bolus(waitForSuggestion: false, fetch: false))
-//                    }) {
-//                        Image(systemName: "plus.circle.fill")
-//                            .font(.system(size: 45))
-//                            .foregroundStyle(Color.tabBar)
-//                            .padding(.bottom, 2)
-//                    }
-//                    Spacer()
-//                    tabBarButton(
-//                        index: 2,
-//                        systemName: selectedTab == 2 ? "person.fill" : "person",
-//                        label: "Profile"
-//                    )
-//                    Spacer()
-//                    tabBarButton(index: 3, systemName: "text.justify", label: "Menu")
-//                }
-//                .padding(.horizontal, 20)
-//            }.blur(radius: isMenuPresented ? 5 : 0)
-//        }
-
         @ViewBuilder func tabBar() -> some View {
             ZStack(alignment: .bottom) {
                 TabView {
@@ -896,12 +828,17 @@ extension Home {
                             .padding(.horizontal, 20)
                     }
                 )
-            }.ignoresSafeArea(.keyboard, edges: .bottom)
+            }.ignoresSafeArea(.keyboard, edges: .bottom).blur(radius: state.waitForSuggestion ? 8 : 0)
         }
 
         var body: some View {
-            // customTabBar()
-            tabBar()
+            ZStack(alignment: .center) {
+                tabBar()
+
+                if state.waitForSuggestion {
+                    CustomProgressView(text: "Updating IOB...")
+                }
+            }
         }
 
         private var popup: some View {