|
|
@@ -11,11 +11,20 @@ extension DataTable {
|
|
|
@State private var removeCarbsAlert: Alert?
|
|
|
@State private var isRemoveInsulinAlertPresented = false
|
|
|
@State private var removeInsulinAlert: Alert?
|
|
|
+ @State private var showNonPumpInsulin: 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
|
|
|
|
|
|
@Environment(\.colorScheme) var colorScheme
|
|
|
|
|
|
+ private var insulinFormatter: NumberFormatter {
|
|
|
+ let formatter = NumberFormatter()
|
|
|
+ formatter.numberStyle = .decimal
|
|
|
+ formatter.maximumFractionDigits = 2
|
|
|
+ return formatter
|
|
|
+ }
|
|
|
+
|
|
|
private var glucoseFormatter: NumberFormatter {
|
|
|
let formatter = NumberFormatter()
|
|
|
formatter.numberStyle = .decimal
|
|
|
@@ -57,12 +66,59 @@ extension DataTable {
|
|
|
.sheet(isPresented: $showManualGlucose) {
|
|
|
addGlucoseView
|
|
|
}
|
|
|
+ .sheet(isPresented: $showNonPumpInsulin, onDismiss: { if isAmountUnconfirmed { state.nonPumpInsulinAmount = 0
|
|
|
+ state.nonPumpInsulinDate = Date() } }) {
|
|
|
+ addNonPumpInsulinView
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private var treatmentsList: some View {
|
|
|
List {
|
|
|
- ForEach(state.treatments) { item in
|
|
|
- treatmentView(item)
|
|
|
+ HStack {
|
|
|
+ Button(action: { showFutureEntries.toggle() }, label: {
|
|
|
+ HStack {
|
|
|
+ Image(systemName: showFutureEntries ? "calendar.badge.minus" : "calendar.badge.plus")
|
|
|
+ .foregroundColor(Color.accentColor)
|
|
|
+ Text(showFutureEntries ? "Hide Future" : "Show Future")
|
|
|
+ .foregroundColor(Color.secondary)
|
|
|
+ .font(.caption)
|
|
|
+
|
|
|
+ }.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
+
|
|
|
+ }).buttonStyle(.borderless)
|
|
|
+
|
|
|
+ Spacer()
|
|
|
+
|
|
|
+ Button(action: { showNonPumpInsulin = true
|
|
|
+ state.nonPumpInsulinDate = Date() }, label: {
|
|
|
+ HStack {
|
|
|
+ Text("Add")
|
|
|
+ .foregroundColor(Color.secondary)
|
|
|
+ .font(.caption)
|
|
|
+
|
|
|
+ Image(systemName: "syringe")
|
|
|
+ .foregroundColor(Color.accentColor)
|
|
|
+ }.frame(maxWidth: .infinity, alignment: .trailing)
|
|
|
+
|
|
|
+ }).buttonStyle(.borderless)
|
|
|
+ }
|
|
|
+
|
|
|
+ if !state.treatments.isEmpty {
|
|
|
+ if !showFutureEntries {
|
|
|
+ ForEach(state.treatments.filter { item in
|
|
|
+ item.date <= Date()
|
|
|
+ }) { item in
|
|
|
+ treatmentView(item)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ForEach(state.treatments) { item in
|
|
|
+ treatmentView(item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ HStack {
|
|
|
+ Text("No data.")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -87,7 +143,7 @@ extension DataTable {
|
|
|
.onDelete(perform: deleteGlucose)
|
|
|
} else {
|
|
|
HStack {
|
|
|
- Text(NSLocalizedString("No data.", comment: "No data text when no entries in history list"))
|
|
|
+ Text("No data.")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -162,7 +218,8 @@ extension DataTable {
|
|
|
message: Text(item.amountText),
|
|
|
primaryButton: .destructive(
|
|
|
Text("Delete"),
|
|
|
- action: { state.deleteCarbs(item) }
|
|
|
+ action: {
|
|
|
+ state.deleteCarbs(item) }
|
|
|
),
|
|
|
secondaryButton: .cancel()
|
|
|
)
|
|
|
@@ -219,6 +276,70 @@ extension DataTable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var addNonPumpInsulinView: some View {
|
|
|
+ NavigationView {
|
|
|
+ VStack {
|
|
|
+ Form {
|
|
|
+ Section {
|
|
|
+ HStack {
|
|
|
+ Text("Amount")
|
|
|
+ Spacer()
|
|
|
+ DecimalTextField(
|
|
|
+ "0",
|
|
|
+ value: $state.nonPumpInsulinAmount,
|
|
|
+ formatter: insulinFormatter,
|
|
|
+ autofocus: true,
|
|
|
+ cleanInput: true
|
|
|
+ )
|
|
|
+ Text("U").foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Section {
|
|
|
+ DatePicker("Date", selection: $state.nonPumpInsulinDate, in: ...Date())
|
|
|
+ }
|
|
|
+
|
|
|
+ let amountWarningCondition = (state.nonPumpInsulinAmount > state.maxBolus) &&
|
|
|
+ (state.nonPumpInsulinAmount <= state.maxBolus * 3)
|
|
|
+
|
|
|
+ Section {
|
|
|
+ HStack {
|
|
|
+ Button {
|
|
|
+ state.addNonPumpInsulin()
|
|
|
+ isAmountUnconfirmed = false
|
|
|
+ showNonPumpInsulin = false
|
|
|
+ }
|
|
|
+ label: {
|
|
|
+ Text("Log non-pump insulin")
|
|
|
+ }
|
|
|
+ .foregroundColor(amountWarningCondition ? Color.white : Color.accentColor)
|
|
|
+ .frame(maxWidth: .infinity, alignment: .center)
|
|
|
+ .disabled(
|
|
|
+ state.nonPumpInsulinAmount <= 0 || state.nonPumpInsulinAmount > state
|
|
|
+ .maxBolus * 3
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ header: {
|
|
|
+ if amountWarningCondition
|
|
|
+ {
|
|
|
+ Text("⚠️ Warning! The entered insulin amount is greater than your Max Bolus setting!")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .listRowBackground(
|
|
|
+ amountWarningCondition ? Color
|
|
|
+ .red : colorScheme == .dark ? Color(UIColor.secondarySystemBackground) : Color.white
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .onAppear(perform: configureView)
|
|
|
+ .navigationTitle("Non-Pump Insulin")
|
|
|
+ .navigationBarTitleDisplayMode(.inline)
|
|
|
+ .navigationBarItems(leading: Button("Close", action: { showNonPumpInsulin = false
|
|
|
+ state.nonPumpInsulinAmount = 0 }))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@ViewBuilder private func glucoseView(_ item: Glucose, isManual: BloodGlucose) -> some View {
|
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
|
HStack {
|