Skip to content

Commit

Permalink
Small fixes for new bolus calc (nightscout#290)
Browse files Browse the repository at this point in the history
* update enact bolus button description when amount exceeds maxBolus and fix insulin unit description

* reimplement continue without bolus button, delete unnecessary code in BolusStateModel

* refactor code and let add insulin button be disabled if maxBolus is exceeded

* remove unused variable
  • Loading branch information
polscm32 committed Oct 30, 2023
1 parent a5156a6 commit b8ea284
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
28 changes: 0 additions & 28 deletions FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ extension Bolus {
fattyMeals = settings.settings.fattyMeals
fattyMealFactor = settings.settings.fattyMealFactor

// get carb ratio entry schedule

if waitForSuggestionInitial {
apsManager.determineBasal()
.receive(on: DispatchQueue.main)
Expand Down Expand Up @@ -173,32 +171,6 @@ extension Bolus {
.store(in: &lifetime)
}

func addWithoutBolus() {
guard amount > 0 else {
showModal(for: nil)
return
}
amount = min(amount, maxBolus * 3)

pumpHistoryStorage.storeEvents(
[
PumpHistoryEvent(
id: UUID().uuidString,
type: .bolus,
timestamp: Date(),
amount: amount,
duration: nil,
durationMin: nil,
rate: nil,
temp: nil,
carbInput: nil,
isExternal: true
)
]
)
showModal(for: nil)
}

func setupInsulinRequired() {
DispatchQueue.main.async {
self.insulinRequired = self.provider.suggestion?.insulinReq ?? 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extension Bolus {
@ObservedObject var state: StateModel

@State private var showInfo = false
@State private var exceededMaxBolus = false
@State var insulinCalculated: Decimal = 0

@Environment(\.colorScheme) var colorScheme
Expand Down Expand Up @@ -136,23 +137,36 @@ extension Bolus {
autofocus: false,
cleanInput: true
)
Text(!(state.amount > state.maxBolus) ? "U" : "😵").foregroundColor(.secondary)
Text(exceededMaxBolus ? "😵" : " U").foregroundColor(.secondary)
}
.onChange(of: state.amount) { newValue in
if newValue > state.maxBolus {
exceededMaxBolus = true
} else {
exceededMaxBolus = false
}
}
}
}
}
header: { Text("Bolus") }

Section {
Button(action: {
state.add()
}) {
Text(!(state.amount > state.maxBolus) ? "Enact bolus" : "Max Bolus exceeded!")
.frame(maxWidth: .infinity, alignment: .center)
if state.amount == 0 {
Button { state.showModal(for: nil) }
label: { Text("Continue without bolus") }.frame(maxWidth: .infinity, alignment: .center)
} else {
Button(action: {
state.add()
}) {
Text(exceededMaxBolus ? "Max Bolus exceeded!" : "Enact bolus")
.frame(maxWidth: .infinity, alignment: .center)
}
.foregroundColor(exceededMaxBolus ? .loopRed : .accentColor)
.disabled(
state.amount <= 0 || state.amount > state.maxBolus
)
}
.disabled(
state.amount <= 0 || state.amount > state.maxBolus
)
}
.onAppear {
configureView {
Expand Down Expand Up @@ -387,13 +401,26 @@ extension Bolus {
.foregroundColor(.secondary)
}
.padding()

if exceededMaxBolus {
HStack {
let maxBolus = state.maxBolus
let maxBolusFormatted = maxBolus.formatted()
Text("Your entered amount was limited by your max Bolus setting of \(maxBolusFormatted)\(unit)!")
}
.padding()
.fontWeight(.semibold)
.foregroundStyle(Color.loopRed)
}
}
.padding(.top, 10)
.padding(.bottom, 15)

// Hide button
VStack {
Button { showInfo = false }
Button {
showInfo = false
}
label: {
Text("OK")
}
Expand Down

0 comments on commit b8ea284

Please sign in to comment.