|
|
@@ -6,6 +6,7 @@ extension Bolus {
|
|
|
struct AlternativeBolusCalcRootView: BaseView {
|
|
|
let resolver: Resolver
|
|
|
let waitForSuggestion: Bool
|
|
|
+ let meal: [CarbsEntry]?
|
|
|
@ObservedObject var state: StateModel
|
|
|
|
|
|
@State private var showInfo = false
|
|
|
@@ -97,15 +98,65 @@ extension Bolus {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } header: { Text("Values") }
|
|
|
+
|
|
|
+ if changed {
|
|
|
+ Section {
|
|
|
+ VStack {
|
|
|
+ if let mealEntry = meal {
|
|
|
+ if (mealEntry.first?.carbs ?? 0) > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Carbs")
|
|
|
+ Spacer()
|
|
|
+ Text((mealEntry.first?.carbs ?? 0).formatted())
|
|
|
+ Text("g")
|
|
|
+ }.foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ if (mealEntry.first?.fat ?? 0) > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Fat")
|
|
|
+ Spacer()
|
|
|
+ Text((mealEntry.first?.fat ?? 0).formatted())
|
|
|
+ Text("g")
|
|
|
+ }.foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ if (mealEntry.first?.protein ?? 0) > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Protein")
|
|
|
+ Spacer()
|
|
|
+ Text((mealEntry.first?.protein ?? 0).formatted())
|
|
|
+ Text("g")
|
|
|
+ }.foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ if (mealEntry.first?.note ?? "") != "" {
|
|
|
+ HStack {
|
|
|
+ Text("Note")
|
|
|
+ Spacer()
|
|
|
+ Text(mealEntry.first?.note ?? "")
|
|
|
+ }.foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } header: { Text("Meal Summary") }
|
|
|
+ }
|
|
|
+
|
|
|
+ if changed {
|
|
|
+ Section {
|
|
|
+ Button {
|
|
|
+ if let exists = meal {
|
|
|
+ state.backToCarbsView(exists, hasFatOrProtein)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ label: { Text("Edit Meal") }.frame(maxWidth: .infinity, alignment: .center)
|
|
|
+ }
|
|
|
}
|
|
|
- header: { Text("Values") }
|
|
|
|
|
|
Section {
|
|
|
if state.waitForSuggestion {
|
|
|
HStack {
|
|
|
Text("Wait please").foregroundColor(.secondary)
|
|
|
Spacer()
|
|
|
- ActivityIndicator(isAnimating: .constant(true), style: .medium) // fix iOS 15 bug
|
|
|
+ ActivityIndicator(isAnimating: .constant(true), style: .medium)
|
|
|
}
|
|
|
} else {
|
|
|
HStack {
|
|
|
@@ -172,6 +223,7 @@ extension Bolus {
|
|
|
configureView {
|
|
|
state.waitForSuggestionInitial = waitForSuggestion
|
|
|
state.waitForSuggestion = waitForSuggestion
|
|
|
+ insulinCalculated = state.calculateInsulin()
|
|
|
}
|
|
|
}
|
|
|
.navigationTitle("Enact Bolus")
|
|
|
@@ -184,6 +236,20 @@ extension Bolus {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var changed: Bool {
|
|
|
+ if let exists = meal {
|
|
|
+ return ((exists.first?.carbs ?? 0) > 0 || (exists.first?.fat ?? 0) > 0 || (exists.first?.protein ?? 0) > 0)
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ var hasFatOrProtein: Bool {
|
|
|
+ if let exists = meal {
|
|
|
+ return ((exists.first?.fat ?? 0) > 0 || (exists.first?.protein ?? 0) > 0)
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
// calculation showed in popup
|
|
|
var bolusInfoAlternativeCalculator: some View {
|
|
|
let unit = NSLocalizedString(
|
|
|
@@ -193,7 +259,7 @@ extension Bolus {
|
|
|
|
|
|
return VStack {
|
|
|
VStack {
|
|
|
- VStack {
|
|
|
+ VStack(spacing: 5) {
|
|
|
HStack {
|
|
|
Text("Calculations")
|
|
|
.font(.title3)
|
|
|
@@ -201,6 +267,46 @@ extension Bolus {
|
|
|
Spacer()
|
|
|
}
|
|
|
.padding(.vertical, 10)
|
|
|
+
|
|
|
+ if changed {
|
|
|
+ VStack(spacing: 3) {
|
|
|
+ if let mealEntry = meal {
|
|
|
+ if (mealEntry.first?.note ?? "") != "" {
|
|
|
+ HStack {
|
|
|
+ Text("Note")
|
|
|
+ .foregroundColor(.secondary)
|
|
|
+ Spacer()
|
|
|
+ Text(mealEntry.first?.note ?? "").foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mealEntry.first?.carbs ?? 0) > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Carbs")
|
|
|
+ .foregroundColor(.secondary)
|
|
|
+ Spacer()
|
|
|
+ Text((mealEntry.first?.carbs ?? 0).formatted())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mealEntry.first?.protein ?? 0) > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Protein")
|
|
|
+ .foregroundColor(.secondary)
|
|
|
+ Spacer()
|
|
|
+ Text((mealEntry.first?.protein ?? 0).formatted())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mealEntry.first?.fat ?? 0) > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Fat")
|
|
|
+ .foregroundColor(.secondary)
|
|
|
+ Spacer()
|
|
|
+ Text((mealEntry.first?.fat ?? 0).formatted())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.padding(.bottom, 20)
|
|
|
+ }
|
|
|
+
|
|
|
HStack {
|
|
|
Text("Carb Ratio")
|
|
|
.foregroundColor(.secondary)
|