|
|
@@ -264,225 +264,258 @@ extension Bolus {
|
|
|
}
|
|
|
|
|
|
var body: some View {
|
|
|
- Form {
|
|
|
- // MARK: ADDED
|
|
|
-
|
|
|
- Section {
|
|
|
- HStack {
|
|
|
- Text("Carbs").fontWeight(.semibold)
|
|
|
- Spacer()
|
|
|
- DecimalTextField(
|
|
|
- "0",
|
|
|
- value: $state.carbs,
|
|
|
- formatter: formatter,
|
|
|
- autofocus: false,
|
|
|
- cleanInput: true
|
|
|
- )
|
|
|
- Text("g").foregroundColor(.secondary)
|
|
|
- }
|
|
|
-
|
|
|
- if state.useFPUconversion {
|
|
|
- proteinAndFat()
|
|
|
- }
|
|
|
+ ZStack(alignment: .center) {
|
|
|
+ Form {
|
|
|
+ // MARK: ADDED
|
|
|
|
|
|
- // Summary when combining presets
|
|
|
- if state.waitersNotepad() != "" {
|
|
|
+ Section {
|
|
|
HStack {
|
|
|
- Text("Total")
|
|
|
- let test = state.waitersNotepad().components(separatedBy: ", ").removeDublicates()
|
|
|
- HStack(spacing: 0) {
|
|
|
- ForEach(test, id: \.self) {
|
|
|
- Text($0).foregroundStyle(Color.randomGreen()).font(.footnote)
|
|
|
- Text($0 == test[test.count - 1] ? "" : ", ")
|
|
|
- }
|
|
|
- }.frame(maxWidth: .infinity, alignment: .trailing)
|
|
|
+ Text("Carbs").fontWeight(.semibold)
|
|
|
+ Spacer()
|
|
|
+ DecimalTextField(
|
|
|
+ "0",
|
|
|
+ value: $state.carbs,
|
|
|
+ formatter: formatter,
|
|
|
+ autofocus: false,
|
|
|
+ cleanInput: true
|
|
|
+ )
|
|
|
+ Text("g").foregroundColor(.secondary)
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // Time
|
|
|
- HStack {
|
|
|
- Text("Time").foregroundStyle(Color.secondary)
|
|
|
- Spacer()
|
|
|
- if !pushed {
|
|
|
- Button {
|
|
|
- pushed = true
|
|
|
- } label: { Text("Now") }.buttonStyle(.borderless).foregroundColor(.secondary).padding(.trailing, 5)
|
|
|
- } else {
|
|
|
- Button { state.date = state.date.addingTimeInterval(-15.minutes.timeInterval) }
|
|
|
- label: { Image(systemName: "minus.circle") }.tint(.blue).buttonStyle(.borderless)
|
|
|
- DatePicker(
|
|
|
- "Time",
|
|
|
- selection: $state.date,
|
|
|
- displayedComponents: [.hourAndMinute]
|
|
|
- ).controlSize(.mini)
|
|
|
- .labelsHidden()
|
|
|
- Button {
|
|
|
- state.date = state.date.addingTimeInterval(15.minutes.timeInterval)
|
|
|
- }
|
|
|
- label: { Image(systemName: "plus.circle") }.tint(.blue).buttonStyle(.borderless)
|
|
|
+ if state.useFPUconversion {
|
|
|
+ proteinAndFat()
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- .popover(isPresented: $isPromptPresented) {
|
|
|
- presetPopover
|
|
|
- }
|
|
|
-
|
|
|
- HStack {
|
|
|
- Spacer()
|
|
|
- Button {
|
|
|
- isCalculating = true
|
|
|
- state.insulinCalculated = state.calculateInsulin()
|
|
|
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
- isCalculating = false
|
|
|
+ // Summary when combining presets
|
|
|
+ if state.waitersNotepad() != "" {
|
|
|
+ HStack {
|
|
|
+ Text("Total")
|
|
|
+ let test = state.waitersNotepad().components(separatedBy: ", ").removeDublicates()
|
|
|
+ HStack(spacing: 0) {
|
|
|
+ ForEach(test, id: \.self) {
|
|
|
+ Text($0).foregroundStyle(Color.randomGreen()).font(.footnote)
|
|
|
+ Text($0 == test[test.count - 1] ? "" : ", ")
|
|
|
+ }
|
|
|
+ }.frame(maxWidth: .infinity, alignment: .trailing)
|
|
|
}
|
|
|
}
|
|
|
- label: {
|
|
|
- if !isCalculating {
|
|
|
- Text("Calculate")
|
|
|
+
|
|
|
+ // Time
|
|
|
+ HStack {
|
|
|
+ Text("Time").foregroundStyle(Color.secondary)
|
|
|
+ Spacer()
|
|
|
+ if !pushed {
|
|
|
+ Button {
|
|
|
+ pushed = true
|
|
|
+ } label: { Text("Now") }.buttonStyle(.borderless).foregroundColor(.secondary)
|
|
|
+ .padding(.trailing, 5)
|
|
|
} else {
|
|
|
- ProgressView().progressViewStyle(CircularProgressViewStyle())
|
|
|
+ Button { state.date = state.date.addingTimeInterval(-15.minutes.timeInterval) }
|
|
|
+ label: { Image(systemName: "minus.circle") }.tint(.blue).buttonStyle(.borderless)
|
|
|
+ DatePicker(
|
|
|
+ "Time",
|
|
|
+ selection: $state.date,
|
|
|
+ displayedComponents: [.hourAndMinute]
|
|
|
+ ).controlSize(.mini)
|
|
|
+ .labelsHidden()
|
|
|
+ Button {
|
|
|
+ state.date = state.date.addingTimeInterval(15.minutes.timeInterval)
|
|
|
+ }
|
|
|
+ label: { Image(systemName: "plus.circle") }.tint(.blue).buttonStyle(.borderless)
|
|
|
}
|
|
|
- }.disabled(empty)
|
|
|
-
|
|
|
- Spacer()
|
|
|
- }
|
|
|
- } header: { Text("Carbs") }.listRowBackground(Color.chart)
|
|
|
+ }
|
|
|
|
|
|
- Section {
|
|
|
- mealPresets
|
|
|
- }.listRowBackground(Color.chart)
|
|
|
+ .popover(isPresented: $isPromptPresented) {
|
|
|
+ presetPopover
|
|
|
+ }
|
|
|
|
|
|
- Section {
|
|
|
- HStack {
|
|
|
- Button(action: {
|
|
|
- showInfo.toggle()
|
|
|
- }, label: {
|
|
|
- Image(systemName: "info.circle")
|
|
|
- Text("Calculations")
|
|
|
- })
|
|
|
- .foregroundStyle(.blue)
|
|
|
- .font(.footnote)
|
|
|
- .buttonStyle(PlainButtonStyle())
|
|
|
- .frame(maxWidth: .infinity, alignment: .leading)
|
|
|
-
|
|
|
- if state.fattyMeals {
|
|
|
+ HStack {
|
|
|
Spacer()
|
|
|
- Toggle(isOn: $state.useFattyMealCorrectionFactor) {
|
|
|
- Text("Fatty Meal")
|
|
|
- }
|
|
|
- .toggleStyle(CheckboxToggleStyle())
|
|
|
- .font(.footnote)
|
|
|
- .onChange(of: state.useFattyMealCorrectionFactor) { _ in
|
|
|
+ Button {
|
|
|
+ isCalculating = true
|
|
|
state.insulinCalculated = state.calculateInsulin()
|
|
|
- if state.useFattyMealCorrectionFactor {
|
|
|
- state.useSuperBolus = false
|
|
|
+
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
+ isCalculating = false
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if state.sweetMeals {
|
|
|
+ label: {
|
|
|
+ if !isCalculating {
|
|
|
+ Text("Calculate")
|
|
|
+ } else {
|
|
|
+ ProgressView().progressViewStyle(CircularProgressViewStyle())
|
|
|
+ }
|
|
|
+ }.disabled(empty)
|
|
|
+
|
|
|
Spacer()
|
|
|
- Toggle(isOn: $state.useSuperBolus) {
|
|
|
- Text("Super Bolus")
|
|
|
+ }
|
|
|
+ } header: { Text("Carbs") }.listRowBackground(Color.chart)
|
|
|
+
|
|
|
+ Section {
|
|
|
+ mealPresets
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
+
|
|
|
+ Section {
|
|
|
+ HStack {
|
|
|
+ Button(action: {
|
|
|
+ showInfo.toggle()
|
|
|
+ }, label: {
|
|
|
+ Image(systemName: "info.circle")
|
|
|
+ Text("Calculations")
|
|
|
+ })
|
|
|
+ .foregroundStyle(.blue)
|
|
|
+ .font(.footnote)
|
|
|
+ .buttonStyle(PlainButtonStyle())
|
|
|
+ .frame(maxWidth: .infinity, alignment: .leading)
|
|
|
+
|
|
|
+ if state.fattyMeals {
|
|
|
+ Spacer()
|
|
|
+ Toggle(isOn: $state.useFattyMealCorrectionFactor) {
|
|
|
+ Text("Fatty Meal")
|
|
|
+ }
|
|
|
+ .toggleStyle(CheckboxToggleStyle())
|
|
|
+ .font(.footnote)
|
|
|
+ .onChange(of: state.useFattyMealCorrectionFactor) { _ in
|
|
|
+ state.insulinCalculated = state.calculateInsulin()
|
|
|
+ if state.useFattyMealCorrectionFactor {
|
|
|
+ state.useSuperBolus = false
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- .toggleStyle(CheckboxToggleStyle())
|
|
|
- .font(.footnote)
|
|
|
- .onChange(of: state.useSuperBolus) { _ in
|
|
|
- state.insulinCalculated = state.calculateInsulin()
|
|
|
- if state.useSuperBolus {
|
|
|
- state.useFattyMealCorrectionFactor = false
|
|
|
+ if state.sweetMeals {
|
|
|
+ Spacer()
|
|
|
+ Toggle(isOn: $state.useSuperBolus) {
|
|
|
+ Text("Super Bolus")
|
|
|
+ }
|
|
|
+ .toggleStyle(CheckboxToggleStyle())
|
|
|
+ .font(.footnote)
|
|
|
+ .onChange(of: state.useSuperBolus) { _ in
|
|
|
+ state.insulinCalculated = state.calculateInsulin()
|
|
|
+ if state.useSuperBolus {
|
|
|
+ state.useFattyMealCorrectionFactor = false
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- HStack {
|
|
|
- Text("Recommended Bolus")
|
|
|
- Spacer()
|
|
|
- Text(
|
|
|
- formatter
|
|
|
- .string(from: Double(state.insulinCalculated) as NSNumber) ?? ""
|
|
|
- )
|
|
|
- Text(
|
|
|
- NSLocalizedString(" U", comment: "Unit in number of units delivered (keep the space character!)")
|
|
|
- ).foregroundColor(.secondary)
|
|
|
- }.contentShape(Rectangle())
|
|
|
- .onTapGesture { state.amount = state.insulinCalculated }
|
|
|
-
|
|
|
- HStack {
|
|
|
- Text("Bolus")
|
|
|
- Spacer()
|
|
|
- DecimalTextField(
|
|
|
- "0",
|
|
|
- value: $state.amount,
|
|
|
- formatter: formatter,
|
|
|
- autofocus: false,
|
|
|
- cleanInput: true
|
|
|
- )
|
|
|
- Text(exceededMaxBolus ? "😵" : " U").foregroundColor(.secondary)
|
|
|
- }
|
|
|
- .onChange(of: state.amount) { newValue in
|
|
|
- if newValue > state.maxBolus {
|
|
|
- exceededMaxBolus = true
|
|
|
- } else {
|
|
|
- exceededMaxBolus = false
|
|
|
+ HStack {
|
|
|
+ Text("Recommended Bolus")
|
|
|
+ Spacer()
|
|
|
+ Text(
|
|
|
+ formatter
|
|
|
+ .string(from: Double(state.insulinCalculated) as NSNumber) ?? ""
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ NSLocalizedString(" U", comment: "Unit in number of units delivered (keep the space character!)")
|
|
|
+ ).foregroundColor(.secondary)
|
|
|
+ }.contentShape(Rectangle())
|
|
|
+ .onTapGesture { state.amount = state.insulinCalculated }
|
|
|
+
|
|
|
+ HStack {
|
|
|
+ Text("Bolus")
|
|
|
+ Spacer()
|
|
|
+ DecimalTextField(
|
|
|
+ "0",
|
|
|
+ value: $state.amount,
|
|
|
+ formatter: formatter,
|
|
|
+ autofocus: false,
|
|
|
+ cleanInput: true
|
|
|
+ )
|
|
|
+ Text(exceededMaxBolus ? "😵" : " U").foregroundColor(.secondary)
|
|
|
+ }
|
|
|
+ .onChange(of: state.amount) { newValue in
|
|
|
+ if newValue > state.maxBolus {
|
|
|
+ exceededMaxBolus = true
|
|
|
+ } else {
|
|
|
+ exceededMaxBolus = false
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- } header: { Text("Bolus") }.listRowBackground(Color.chart)
|
|
|
+ } header: { Text("Bolus") }.listRowBackground(Color.chart)
|
|
|
|
|
|
- if state.amount > 0 {
|
|
|
- Section {
|
|
|
- Button {
|
|
|
- Task {
|
|
|
- await state.add()
|
|
|
- state.hideModal()
|
|
|
- state.addCarbs()
|
|
|
+ if state.amount > 0 {
|
|
|
+ Section {
|
|
|
+ Button {
|
|
|
+ Task {
|
|
|
+ await state.add()
|
|
|
+ state.waitForSuggestion = true
|
|
|
+ state.addCarbs()
|
|
|
+ state.addButtonPressed = true
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- label: { Text(exceededMaxBolus ? "Max Bolus exceeded!" : "Enact bolus") }
|
|
|
- .frame(maxWidth: .infinity, alignment: .center)
|
|
|
- .disabled(disabled)
|
|
|
- .listRowBackground(!disabled ? Color(.systemBlue) : Color(.systemGray4))
|
|
|
- .tint(.white)
|
|
|
- }
|
|
|
- }
|
|
|
- if state.amount <= 0 {
|
|
|
- Section {
|
|
|
- Button {
|
|
|
- state.hideModal()
|
|
|
- state.addCarbs()
|
|
|
- }
|
|
|
- label: { Text("Continue without bolus") }.frame(maxWidth: .infinity, alignment: .center)
|
|
|
- }.listRowBackground(Color.chart)
|
|
|
- }
|
|
|
- }.scrollContentBackground(.hidden).background(color)
|
|
|
- .blur(radius: showInfo ? 3 : 0)
|
|
|
- .navigationTitle("Treatments")
|
|
|
- .navigationBarTitleDisplayMode(.large)
|
|
|
- .toolbar(content: {
|
|
|
- ToolbarItem(placement: .topBarLeading) {
|
|
|
- Button {
|
|
|
- state.hideModal()
|
|
|
- } label: {
|
|
|
- Text("Close")
|
|
|
+ label: { Text(exceededMaxBolus ? "Max Bolus exceeded!" : "Enact bolus") }
|
|
|
+ .frame(maxWidth: .infinity, alignment: .center)
|
|
|
+ .disabled(disabled)
|
|
|
+ .listRowBackground(!disabled ? Color(.systemBlue) : Color(.systemGray4))
|
|
|
+ .tint(.white)
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
- .onAppear {
|
|
|
- configureView {
|
|
|
- state.insulinCalculated = state.calculateInsulin()
|
|
|
+ if state.amount <= 0 {
|
|
|
+ Section {
|
|
|
+ Button {
|
|
|
+ // show loading bar only when carbs are actually added
|
|
|
+ if state.carbs > 0 {
|
|
|
+ state.waitForSuggestion = true
|
|
|
+ } else {
|
|
|
+ // otherwise close view, because hideModal() is otherwise only excecuted after a suggestion update, see StateModal
|
|
|
+ state.hideModal()
|
|
|
+ }
|
|
|
+ state.addButtonPressed = true
|
|
|
+ state.addCarbs()
|
|
|
+ }
|
|
|
+ label: { Text("Continue without bolus") }.frame(maxWidth: .infinity, alignment: .center)
|
|
|
+ }.listRowBackground(Color.chart)
|
|
|
}
|
|
|
- }
|
|
|
+ }.blur(radius: state.waitForSuggestion ? 5 : 0)
|
|
|
|
|
|
- .sheet(isPresented: $showInfo) {
|
|
|
- calculationsDetailView
|
|
|
- .presentationDetents(
|
|
|
- [.fraction(0.9), .large],
|
|
|
- selection: $calculatorDetent
|
|
|
- )
|
|
|
+ if state.waitForSuggestion {
|
|
|
+ CustomProgressView(text: progressText)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .scrollContentBackground(.hidden)
|
|
|
+ .background(color)
|
|
|
+ .blur(radius: showInfo ? 3 : 0)
|
|
|
+ .navigationTitle("Treatments")
|
|
|
+ .navigationBarTitleDisplayMode(.large)
|
|
|
+ .toolbar(content: {
|
|
|
+ ToolbarItem(placement: .topBarLeading) {
|
|
|
+ Button {
|
|
|
+ state.hideModal()
|
|
|
+ } label: {
|
|
|
+ Text("Close")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .onAppear {
|
|
|
+ configureView {
|
|
|
+ state.insulinCalculated = state.calculateInsulin()
|
|
|
}
|
|
|
+ }
|
|
|
+ .onDisappear {
|
|
|
+ state.addButtonPressed = false
|
|
|
+ }
|
|
|
+
|
|
|
+ .sheet(isPresented: $showInfo) {
|
|
|
+ calculationsDetailView
|
|
|
+ .presentationDetents(
|
|
|
+ [.fraction(0.9), .large],
|
|
|
+ selection: $calculatorDetent
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var progressText: String {
|
|
|
+ switch (state.amount > 0, state.carbs > 0) {
|
|
|
+ case (true, true):
|
|
|
+ return "Updating COB and IOB..."
|
|
|
+ case (false, true):
|
|
|
+ return "Updating COB..."
|
|
|
+ case (true, false):
|
|
|
+ return "Updating IOB..."
|
|
|
+ default:
|
|
|
+ return "Updating Treatments..."
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
var predictionChart: some View {
|