|
|
@@ -12,7 +12,6 @@ extension DataTable {
|
|
|
@State private var alertTreatmentToDelete: Treatment?
|
|
|
@State private var alertGlucoseToDelete: Glucose?
|
|
|
|
|
|
- @State private var showExternalInsulin: Bool = false
|
|
|
@State private var showFutureEntries: Bool = false // default to hide future entries
|
|
|
@State private var showManualGlucose: Bool = false
|
|
|
@State private var isAmountUnconfirmed: Bool = true
|
|
|
@@ -109,7 +108,7 @@ extension DataTable {
|
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
|
switch state.mode {
|
|
|
case .treatments: addButton({
|
|
|
- showExternalInsulin = true
|
|
|
+ state.showExternalInsulin = true
|
|
|
state.externalInsulinDate = Date()
|
|
|
})
|
|
|
case .meals: EmptyView()
|
|
|
@@ -123,8 +122,11 @@ extension DataTable {
|
|
|
.sheet(isPresented: $showManualGlucose) {
|
|
|
addGlucoseView()
|
|
|
}
|
|
|
- .sheet(isPresented: $showExternalInsulin, onDismiss: { if isAmountUnconfirmed { state.externalInsulinAmount = 0
|
|
|
- state.externalInsulinDate = Date() } }) {
|
|
|
+ .sheet(
|
|
|
+ isPresented: $state.showExternalInsulin,
|
|
|
+ onDismiss: { if isAmountUnconfirmed { state.externalInsulinAmount = 0
|
|
|
+ state.externalInsulinDate = Date() } }
|
|
|
+ ) {
|
|
|
addExternalInsulinView()
|
|
|
}
|
|
|
}
|
|
|
@@ -392,85 +394,95 @@ extension DataTable {
|
|
|
|
|
|
@ViewBuilder func addExternalInsulinView() -> some View {
|
|
|
NavigationView {
|
|
|
- VStack {
|
|
|
- Form {
|
|
|
- Section {
|
|
|
- HStack {
|
|
|
- Text("Amount")
|
|
|
- Spacer()
|
|
|
- DecimalTextField(
|
|
|
- "0",
|
|
|
- value: $state.externalInsulinAmount,
|
|
|
- formatter: insulinFormatter,
|
|
|
- autofocus: true,
|
|
|
- cleanInput: true
|
|
|
- )
|
|
|
- Text("U").foregroundColor(.secondary)
|
|
|
- }
|
|
|
- }.listRowBackground(Color.chart)
|
|
|
+ ZStack(alignment: .center) {
|
|
|
+ VStack {
|
|
|
+ Form {
|
|
|
+ Section {
|
|
|
+ HStack {
|
|
|
+ Text("Amount")
|
|
|
+ Spacer()
|
|
|
+ DecimalTextField(
|
|
|
+ "0",
|
|
|
+ value: $state.externalInsulinAmount,
|
|
|
+ formatter: insulinFormatter,
|
|
|
+ autofocus: true,
|
|
|
+ cleanInput: true
|
|
|
+ )
|
|
|
+ Text("U").foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
|
|
|
- Section {
|
|
|
- DatePicker("Date", selection: $state.externalInsulinDate, in: ...Date())
|
|
|
- }.listRowBackground(Color.chart)
|
|
|
+ Section {
|
|
|
+ DatePicker("Date", selection: $state.externalInsulinDate, in: ...Date())
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
|
|
|
- let amountWarningCondition = (state.externalInsulinAmount > state.maxBolus)
|
|
|
+ let amountWarningCondition = (state.externalInsulinAmount > state.maxBolus)
|
|
|
|
|
|
- var listBackgroundColor: Color {
|
|
|
- if amountWarningCondition {
|
|
|
- return Color.red
|
|
|
- } else if state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3 {
|
|
|
- return Color(.systemGray4)
|
|
|
- } else {
|
|
|
- return Color(.systemBlue)
|
|
|
+ var listBackgroundColor: Color {
|
|
|
+ if amountWarningCondition {
|
|
|
+ return Color.red
|
|
|
+ } else if state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3 {
|
|
|
+ return Color(.systemGray4)
|
|
|
+ } else {
|
|
|
+ return Color(.systemBlue)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- var foregroundColor: Color {
|
|
|
- if amountWarningCondition {
|
|
|
- return Color.white
|
|
|
- } else if state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3 {
|
|
|
- return Color.secondary
|
|
|
- } else {
|
|
|
- return Color.white
|
|
|
+ var foregroundColor: Color {
|
|
|
+ if amountWarningCondition {
|
|
|
+ return Color.white
|
|
|
+ } else if state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3 {
|
|
|
+ return Color.secondary
|
|
|
+ } else {
|
|
|
+ return Color.white
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- Section {
|
|
|
- HStack {
|
|
|
- Button {
|
|
|
- Task {
|
|
|
- do {
|
|
|
- await state.addExternalInsulin()
|
|
|
- isAmountUnconfirmed = false
|
|
|
- showExternalInsulin = false
|
|
|
+ Section {
|
|
|
+ HStack {
|
|
|
+ Button {
|
|
|
+ Task {
|
|
|
+ do {
|
|
|
+ await state.addExternalInsulin()
|
|
|
+ state.waitForSuggestion = true
|
|
|
+ state.addButtonPressed = true
|
|
|
+ isAmountUnconfirmed = false
|
|
|
+ }
|
|
|
}
|
|
|
+ } label: {
|
|
|
+ Text("Log external insulin")
|
|
|
}
|
|
|
- } label: {
|
|
|
- Text("Log external insulin")
|
|
|
+ .foregroundStyle(foregroundColor)
|
|
|
+ .frame(maxWidth: .infinity, alignment: .center)
|
|
|
+ .disabled(
|
|
|
+ state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3
|
|
|
+ )
|
|
|
}
|
|
|
- .foregroundStyle(foregroundColor)
|
|
|
- .frame(maxWidth: .infinity, alignment: .center)
|
|
|
- .disabled(
|
|
|
- state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3
|
|
|
- )
|
|
|
}
|
|
|
- }
|
|
|
- header: {
|
|
|
- if amountWarningCondition
|
|
|
- {
|
|
|
- Text("⚠️ Warning! The entered insulin amount is greater than your Max Bolus setting!")
|
|
|
+ header: {
|
|
|
+ if amountWarningCondition
|
|
|
+ {
|
|
|
+ Text("⚠️ Warning! The entered insulin amount is greater than your Max Bolus setting!")
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- .listRowBackground(listBackgroundColor).tint(.white)
|
|
|
- }.scrollContentBackground(.hidden).background(color)
|
|
|
+ .listRowBackground(listBackgroundColor).tint(.white)
|
|
|
+ }.scrollContentBackground(.hidden).background(color)
|
|
|
+ }.blur(radius: state.waitForSuggestion ? 5 : 0)
|
|
|
+
|
|
|
+ if state.waitForSuggestion {
|
|
|
+ CustomProgressView(text: "Updating IOB")
|
|
|
+ }
|
|
|
}
|
|
|
.onAppear(perform: configureView)
|
|
|
+ .onDisappear {
|
|
|
+ state.addButtonPressed = false
|
|
|
+ }
|
|
|
.navigationTitle("External Insulin")
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
.toolbar {
|
|
|
ToolbarItem(placement: .topBarLeading) {
|
|
|
Button("Close") {
|
|
|
- showExternalInsulin = false
|
|
|
+ state.showExternalInsulin = false
|
|
|
state.externalInsulinAmount = 0
|
|
|
}
|
|
|
}
|