Jelajahi Sumber

UI
* add carbs only via carb button
* move close button to .topBarLeading
* move add insulin button in history view to .topBarTrailing

polscm32 2 tahun lalu
induk
melakukan
c04b049078

+ 7 - 1
FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift

@@ -151,7 +151,13 @@ extension AddCarbs {
                 }
                 .navigationTitle("Add Meal")
                 .navigationBarTitleDisplayMode(.inline)
-                .navigationBarItems(trailing: Button("Close", action: state.hideModal))
+                .toolbar {
+                    ToolbarItem(placement: .topBarLeading) {
+                        Button("Close") {
+                            state.hideModal()
+                        }
+                    }
+                }
         }
 
         private var presetPopover: some View {

+ 7 - 1
FreeAPS/Sources/Modules/AddTempTarget/View/AddTempTargetRootView.swift

@@ -162,7 +162,13 @@ extension AddTempTarget {
                 }
                 .navigationTitle("Enact Temp Target")
                 .navigationBarTitleDisplayMode(.inline)
-                .navigationBarItems(trailing: Button("Close", action: state.hideModal))
+                .toolbar {
+                    ToolbarItem(placement: .navigationBarLeading) {
+                        Button("Close") {
+                            state.hideModal()
+                        }
+                    }
+                }
         }
 
         private func presetView(for preset: TempTarget) -> some View {

+ 20 - 18
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -201,19 +201,25 @@ extension Bolus {
                 .blur(radius: showInfo ? 3 : 0)
                 .navigationTitle("Enact Bolus")
                 .navigationBarTitleDisplayMode(.inline)
-                .navigationBarItems(
-                    leading: Button {
-                        carbsView()
-                    }
-                    label: {
-                        HStack {
-                            Image(systemName: "chevron.backward")
-                            Text("Meal")
+                .toolbar {
+                    ToolbarItem(placement: .topBarLeading) {
+                        if !fetch {
+                            Button("Close") {
+                                state.hideModal()
+                            }
+                        } else {
+                            Button {
+                                carbsView()
+                            } label: {
+                                HStack {
+                                    Image(systemName: "chevron.backward")
+                                    Text("Meal")
+                                }
+                            }
                         }
-                    },
-                    trailing: Button { state.hideModal() }
-                    label: { Text("Close") }
-                )
+                    }
+                }
+
                 .onAppear {
                     configureView {
                         state.waitForSuggestionInitial = waitForSuggestion
@@ -695,12 +701,8 @@ extension Bolus {
         }
 
         func carbsView() {
-            if fetch {
-                keepForNextWiew = true
-                state.backToCarbsView(complexEntry: true, meal, override: false)
-            } else {
-                state.backToCarbsView(complexEntry: false, meal, override: true)
-            }
+            keepForNextWiew = true
+            state.backToCarbsView(complexEntry: true, meal, override: false)
         }
 
         var mealEntries: some View {

+ 19 - 18
FreeAPS/Sources/Modules/Bolus/View/DefaultBolusCalcRootView.swift

@@ -170,19 +170,24 @@ extension Bolus {
 
                 .navigationTitle("Enact Bolus")
                 .navigationBarTitleDisplayMode(.inline)
-                .navigationBarItems(
-                    leading: Button {
-                        carbsView()
-                    }
-                    label: {
-                        HStack {
-                            Image(systemName: "chevron.backward")
-                            Text("Meal")
+                .toolbar {
+                    ToolbarItem(placement: .topBarLeading) {
+                        if !fetch {
+                            Button("Close") {
+                                state.hideModal()
+                            }
+                        } else {
+                            Button {
+                                carbsView()
+                            } label: {
+                                HStack {
+                                    Image(systemName: "chevron.backward")
+                                    Text("Meal")
+                                }
+                            }
                         }
-                    },
-                    trailing: Button { state.hideModal() }
-                    label: { Text("Close") }
-                )
+                    }
+                }
                 .popup(isPresented: presentInfo, alignment: .center, direction: .bottom) {
                     bolusInfo
                 }
@@ -210,12 +215,8 @@ extension Bolus {
         }
 
         func carbsView() {
-            if fetch {
-                keepForNextWiew = true
-                state.backToCarbsView(complexEntry: fetch, meal, override: false)
-            } else {
-                state.backToCarbsView(complexEntry: false, meal, override: true)
-            }
+            keepForNextWiew = true
+            state.backToCarbsView(complexEntry: true, meal, override: false)
         }
 
         var mealEntries: some View {

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

@@ -107,7 +107,20 @@ extension DataTable {
                 .onAppear(perform: configureView)
                 .navigationTitle("History")
                 .navigationBarTitleDisplayMode(.inline)
-                .navigationBarItems(trailing: Button("Close", action: state.hideModal))
+                .toolbar {
+                    ToolbarItem(placement: .topBarLeading) {
+                        Button("Close") {
+                            state.hideModal()
+                        }
+                    }
+                    ToolbarItem(placement: .topBarTrailing) {
+                        switch state.mode {
+                        case .treatments: addInsulinButton
+                        case .meals: EmptyView()
+                        case .glucose: addGlucoseButton
+                        }
+                    }
+                }
                 .sheet(isPresented: $showManualGlucose) {
                     addGlucoseView
                 }
@@ -116,23 +129,39 @@ extension DataTable {
                     addExternalInsulinView
                 }
         }
+        
+        private var addGlucoseButton: some View {
+            Button(
+                action: { showManualGlucose = true
+                    state.manualGlucose = 0 },
+                label: { 
+                    Image(systemName: "plus.circle.fill")
+                    Text("Add")
+                }
+            )
+        }
+        
+        private var addInsulinButton: some View {
+            Button(action: { showExternalInsulin = true
+               state.externalInsulinDate = Date() }, label: {
+               HStack {
+                   Image(systemName: "plus.circle.fill")
+                   Text("Add")
+               }
+           })
+        }
 
         private var treatmentsList: some View {
             List {
                 HStack {
-                    Button(action: { showExternalInsulin = true
-                        state.externalInsulinDate = Date() }, label: {
-                        HStack {
-                            Image(systemName: "syringe")
-                            Text("Add")
-                                .foregroundColor(Color.secondary)
-                                .font(.caption)
-                        }.frame(maxWidth: .infinity, alignment: .leading)
-                    }).buttonStyle(.borderless)
-
                     if state.historyLayout == .twoTabs {
+                        Text("Insulin").foregroundStyle(.secondary)
                         Spacer()
                         filterEntriesButton
+                    } else {
+                        Text("Insulin").foregroundStyle(.secondary)
+                        Spacer()
+                        Text("Time").foregroundStyle(.secondary)
                     }
                 }
                 if !state.treatments.isEmpty {
@@ -169,13 +198,7 @@ extension DataTable {
         private var glucoseList: some View {
             List {
                 HStack {
-                    Button(
-                        action: { showManualGlucose = true
-                            state.manualGlucose = 0 },
-                        label: { Image(systemName: "plus.circle.fill").foregroundStyle(.secondary)
-                        }
-                    ).buttonStyle(.borderless)
-                    Text(state.units.rawValue).foregroundStyle(.secondary)
+                   Text("Values").foregroundStyle(.secondary)
                     Spacer()
                     Text("Time").foregroundStyle(.secondary)
                 }
@@ -228,7 +251,13 @@ extension DataTable {
                 .onAppear(perform: configureView)
                 .navigationTitle("Add Glucose")
                 .navigationBarTitleDisplayMode(.automatic)
-                .navigationBarItems(trailing: Button("Close", action: { showManualGlucose = false }))
+                .toolbar {
+                    ToolbarItem(placement: .topBarLeading) {
+                        Button("Close") {
+                            showManualGlucose = false
+                        }
+                    }
+                }
             }
         }
 
@@ -237,7 +266,6 @@ extension DataTable {
                 HStack {
                     Text(showFutureEntries ? "Hide Future" : "Show Future")
                         .foregroundColor(Color.secondary)
-                        .font(.caption)
                     Image(systemName: showFutureEntries ? "calendar.badge.minus" : "calendar.badge.plus")
                 }.frame(maxWidth: .infinity, alignment: .trailing)
             }).buttonStyle(.borderless)

+ 7 - 1
FreeAPS/Sources/Modules/OverrideProfilesConfig/View/OverrideProfilesRootView.swift

@@ -307,7 +307,13 @@ extension OverrideProfilesConfig {
                 .onAppear { state.savedSettings() }
                 .navigationBarTitle("Profiles")
                 .navigationBarTitleDisplayMode(.inline)
-                .navigationBarItems(trailing: Button("Close", action: state.hideModal))
+                .toolbar {
+                    ToolbarItem(placement: .navigationBarLeading) {
+                        Button("Close") {
+                            state.hideModal()
+                        }
+                    }
+                }
         }
 
         @ViewBuilder private func profilesView(for preset: OverridePresets) -> some View {

+ 7 - 1
FreeAPS/Sources/Modules/Settings/View/SettingsRootView.swift

@@ -154,7 +154,13 @@ extension Settings {
                 }
                 .onAppear(perform: configureView)
                 .navigationTitle("Settings")
-                .navigationBarItems(trailing: Button("Close", action: state.hideSettingsModal))
+                .toolbar {
+                    ToolbarItem(placement: .topBarLeading) {
+                        Button("Close") {
+                            state.hideSettingsModal()
+                        }
+                    }
+                }
                 .navigationBarTitleDisplayMode(.inline)
                 .onDisappear(perform: { state.uploadProfileAndSettings(false) })
         }

+ 7 - 1
FreeAPS/Sources/Modules/Stat/View/StatRootView.swift

@@ -170,7 +170,13 @@ extension Stat {
                 .onAppear(perform: configureView)
                 .navigationBarTitle("Statistics")
                 .navigationBarTitleDisplayMode(.inline)
-                .navigationBarItems(trailing: Button("Close", action: state.hideModal))
+                .toolbar {
+                    ToolbarItem(placement: .topBarLeading) {
+                        Button("Close") {
+                            state.hideModal()
+                        }
+                    }
+                }
         }
     }
 }

+ 0 - 1
FreeAPS/Sources/Modules/StatConfig/View/StatConfigRootView.swift

@@ -102,7 +102,6 @@ extension StatConfig {
             .onAppear(perform: configureView)
             .navigationBarTitle("UI/UX")
             .navigationBarTitleDisplayMode(.automatic)
-            .navigationBarItems(trailing: Button("Close", action: state.hideModal))
         }
     }
 }