|
|
@@ -37,53 +37,17 @@ extension Bolus {
|
|
|
Form {
|
|
|
if fetch {
|
|
|
Section {
|
|
|
- VStack {
|
|
|
- if let carbs = meal.first?.carbs, carbs > 0 {
|
|
|
- HStack {
|
|
|
- Text("Carbs")
|
|
|
- Spacer()
|
|
|
- Text(carbs.formatted())
|
|
|
- Text("g")
|
|
|
- }.foregroundColor(.secondary)
|
|
|
- }
|
|
|
- if let fat = meal.first?.fat, fat > 0 {
|
|
|
- HStack {
|
|
|
- Text("Fat")
|
|
|
- Spacer()
|
|
|
- Text(fat.formatted())
|
|
|
- Text("g")
|
|
|
- }.foregroundColor(.secondary)
|
|
|
- }
|
|
|
- if let protein = meal.first?.protein, protein > 0 {
|
|
|
- HStack {
|
|
|
- Text("Protein")
|
|
|
- Spacer()
|
|
|
- Text(protein.formatted())
|
|
|
- Text("g")
|
|
|
- }.foregroundColor(.secondary)
|
|
|
- }
|
|
|
- if let note = meal.first?.note, note != "" {
|
|
|
- HStack {
|
|
|
- Text("Note")
|
|
|
- Spacer()
|
|
|
- Text(note)
|
|
|
- }.foregroundColor(.secondary)
|
|
|
- }
|
|
|
- }
|
|
|
+ mealEntries
|
|
|
} header: { Text("Meal Summary") }
|
|
|
}
|
|
|
|
|
|
Section {
|
|
|
- Button {
|
|
|
- let id_ = meal.first?.id ?? ""
|
|
|
- if fetch {
|
|
|
- keepForNextWiew = true
|
|
|
- state.backToCarbsView(complexEntry: fetch, id_)
|
|
|
- } else {
|
|
|
- state.showModal(for: .addCarbs(editMode: false))
|
|
|
+ if !fetch {
|
|
|
+ Button {
|
|
|
+ carbssView()
|
|
|
}
|
|
|
+ label: { Text("Add Meal") }.frame(maxWidth: .infinity, alignment: .center)
|
|
|
}
|
|
|
- label: { Text(fetch ? "Edit Meal" : "Add Meal") }.frame(maxWidth: .infinity, alignment: .center)
|
|
|
} header: { Text(!fetch ? "Meal Summary" : "") }
|
|
|
|
|
|
Section {
|
|
|
@@ -187,7 +151,19 @@ extension Bolus {
|
|
|
|
|
|
.navigationTitle("Enact Bolus")
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
- .navigationBarItems(leading: Button("Close", action: state.hideModal))
|
|
|
+ .navigationBarItems(
|
|
|
+ leading: Button {
|
|
|
+ if fetch {
|
|
|
+ carbssView()
|
|
|
+ } else {
|
|
|
+ state.hideModal()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ label: { Text("Back") },
|
|
|
+
|
|
|
+ trailing: Button { state.hideModal() }
|
|
|
+ label: { Text("Close") }
|
|
|
+ )
|
|
|
.popup(isPresented: presentInfo, alignment: .center, direction: .bottom) {
|
|
|
bolusInfo
|
|
|
}
|
|
|
@@ -201,6 +177,52 @@ extension Bolus {
|
|
|
((meal.first?.fat ?? 0) > 0) || ((meal.first?.protein ?? 0) > 0)
|
|
|
}
|
|
|
|
|
|
+ func carbssView() {
|
|
|
+ let id_ = meal.first?.id ?? ""
|
|
|
+ if fetch {
|
|
|
+ keepForNextWiew = true
|
|
|
+ state.backToCarbsView(complexEntry: fetch, id_)
|
|
|
+ } else {
|
|
|
+ state.showModal(for: .addCarbs(editMode: false))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var mealEntries: some View {
|
|
|
+ VStack {
|
|
|
+ if let carbs = meal.first?.carbs, carbs > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Carbs")
|
|
|
+ Spacer()
|
|
|
+ Text(carbs.formatted())
|
|
|
+ Text("g")
|
|
|
+ }.foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ if let fat = meal.first?.fat, fat > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Fat")
|
|
|
+ Spacer()
|
|
|
+ Text(fat.formatted())
|
|
|
+ Text("g")
|
|
|
+ }.foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ if let protein = meal.first?.protein, protein > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Protein")
|
|
|
+ Spacer()
|
|
|
+ Text(protein.formatted())
|
|
|
+ Text("g")
|
|
|
+ }.foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ if let note = meal.first?.note, note != "" {
|
|
|
+ HStack {
|
|
|
+ Text("Note")
|
|
|
+ Spacer()
|
|
|
+ Text(note)
|
|
|
+ }.foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var bolusInfo: some View {
|
|
|
VStack {
|
|
|
// Variables
|