Procházet zdrojové kódy

add custom progress view when deleting carbs/insulin from history

polscm32 před 2 roky
rodič
revize
71f2784163

+ 2 - 0
FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift

@@ -163,6 +163,7 @@ extension DataTable {
 
         func deleteCarbs(_ treatment: Treatment) {
             provider.deleteCarbs(treatment)
+            apsManager.determineBasalSync()
         }
 
         func deleteInsulin(_ treatment: Treatment) async {
@@ -170,6 +171,7 @@ extension DataTable {
                 let authenticated = try await unlockmanager.unlock()
                 if authenticated {
                     provider.deleteInsulin(treatment)
+                    apsManager.determineBasalSync()
                 } else {
                     print("authentication failed")
                 }

+ 58 - 48
FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift

@@ -74,61 +74,68 @@ extension DataTable {
         }
 
         var body: some View {
-            VStack {
-                Picker("Mode", selection: $state.mode) {
-                    ForEach(
-                        Mode.allCases.filter({ state.historyLayout == .twoTabs ? $0 != .meals : true }).indexed(),
-                        id: \.1
-                    ) { index, item in
-                        if state.historyLayout == .threeTabs && item == .treatments {
-                            Text("Insulin")
-                                .tag(index)
-                        } else {
-                            Text(item.name)
-                                .tag(index)
+            ZStack(alignment: .center) {
+                VStack {
+                    Picker("Mode", selection: $state.mode) {
+                        ForEach(
+                            Mode.allCases.filter({ state.historyLayout == .twoTabs ? $0 != .meals : true }).indexed(),
+                            id: \.1
+                        ) { index, item in
+                            if state.historyLayout == .threeTabs && item == .treatments {
+                                Text("Insulin")
+                                    .tag(index)
+                            } else {
+                                Text(item.name)
+                                    .tag(index)
+                            }
                         }
                     }
-                }
-                .pickerStyle(SegmentedPickerStyle())
-                .padding(.horizontal)
+                    .pickerStyle(SegmentedPickerStyle())
+                    .padding(.horizontal)
 
-                Form {
-                    switch state.mode {
-                    case .treatments: treatmentsList
-                    case .glucose: glucoseList
-                    case .meals: state.historyLayout == .threeTabs ? AnyView(mealsList) : AnyView(EmptyView())
-                    }
-                }.scrollContentBackground(.hidden)
-                    .background(color)
-            }.background(color)
-                .onAppear(perform: configureView)
-                .navigationTitle("History")
-                .navigationBarTitleDisplayMode(.large)
-                .toolbar {
-                    ToolbarItem(placement: .topBarTrailing) {
+                    Form {
                         switch state.mode {
-                        case .treatments: addButton({
-                                state.showExternalInsulin = true
-                                state.externalInsulinDate = Date()
-                            })
-                        case .meals: EmptyView()
-                        case .glucose: addButton({
-                                showManualGlucose = true
-                                state.manualGlucose = 0
-                            })
+                        case .treatments: treatmentsList
+                        case .glucose: glucoseList
+                        case .meals: state.historyLayout == .threeTabs ? AnyView(mealsList) : AnyView(EmptyView())
                         }
-                    }
-                }
-                .sheet(isPresented: $showManualGlucose) {
-                    addGlucoseView()
+                    }.scrollContentBackground(.hidden)
+                        .background(color)
+                }.blur(radius: state.waitForSuggestion ? 8 : 0)
+
+                if state.waitForSuggestion {
+                    CustomProgressView(text: "Updating History...")
                 }
-                .sheet(
-                    isPresented: $state.showExternalInsulin,
-                    onDismiss: { if isAmountUnconfirmed { state.externalInsulinAmount = 0
-                        state.externalInsulinDate = Date() } }
-                ) {
-                    addExternalInsulinView()
+            }
+            .background(color)
+            .onAppear(perform: configureView)
+            .navigationTitle("History")
+            .navigationBarTitleDisplayMode(.large)
+            .toolbar {
+                ToolbarItem(placement: .topBarTrailing) {
+                    switch state.mode {
+                    case .treatments: addButton({
+                            state.showExternalInsulin = true
+                            state.externalInsulinDate = Date()
+                        })
+                    case .meals: EmptyView()
+                    case .glucose: addButton({
+                            showManualGlucose = true
+                            state.manualGlucose = 0
+                        })
+                    }
                 }
+            }
+            .sheet(isPresented: $showManualGlucose) {
+                addGlucoseView()
+            }
+            .sheet(
+                isPresented: $state.showExternalInsulin,
+                onDismiss: { if isAmountUnconfirmed { state.externalInsulinAmount = 0
+                    state.externalInsulinDate = Date() } }
+            ) {
+                addExternalInsulinView()
+            }
         }
 
         @ViewBuilder func addButton(_ action: @escaping () -> Void) -> some View {
@@ -323,10 +330,12 @@ extension DataTable {
 
                     if state.historyLayout == .twoTabs, treatmentToDelete.type == .carbs || treatmentToDelete.type == .fpus {
                         state.deleteCarbs(treatmentToDelete)
+                        state.waitForSuggestion = true
                     } else {
                         Task {
                             do {
                                 await state.deleteInsulin(treatmentToDelete)
+                                state.waitForSuggestion = true
                             }
                         }
                     }
@@ -386,6 +395,7 @@ extension DataTable {
                     }
 
                     state.deleteCarbs(treatmentToDelete)
+                    state.waitForSuggestion = true
                 }
             } message: {
                 Text("\n" + NSLocalizedString(alertMessage, comment: ""))

+ 2 - 4
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -690,10 +690,8 @@ extension Home {
                     Spacer()
 
                     Button {
-                        Task {
-                            state.waitForSuggestion = true
-                            state.cancelBolus()
-                        }
+                        state.waitForSuggestion = true
+                        state.cancelBolus()
                     } label: {
                         Image(systemName: "xmark.app")
                             .font(.system(size: 25))