|
|
@@ -89,10 +89,12 @@ extension AddTempTarget {
|
|
|
}
|
|
|
|
|
|
if state.viewPercantage {
|
|
|
- Section(
|
|
|
- header: Text("")
|
|
|
- ) {
|
|
|
+ Section {
|
|
|
VStack {
|
|
|
+ Text("\(state.percentage.formatted(.number)) % Insulin")
|
|
|
+ .foregroundColor(isEditing ? .orange : .blue)
|
|
|
+ .font(.largeTitle)
|
|
|
+ .padding(.vertical)
|
|
|
Slider(
|
|
|
value: $state.percentage,
|
|
|
in: 15 ...
|
|
|
@@ -102,33 +104,27 @@ extension AddTempTarget {
|
|
|
isEditing = editing
|
|
|
}
|
|
|
)
|
|
|
- HStack {
|
|
|
- Text("\(state.percentage.formatted(.number)) % Insulin")
|
|
|
- .foregroundColor(isEditing ? .orange : .blue)
|
|
|
- .font(.largeTitle)
|
|
|
- }
|
|
|
+ HStack {}
|
|
|
// Only display target slider when not 100 %
|
|
|
if state.percentage != 100 {
|
|
|
+ Spacer()
|
|
|
Divider()
|
|
|
-
|
|
|
+ Text(
|
|
|
+ (
|
|
|
+ state
|
|
|
+ .units == .mmolL ?
|
|
|
+ "\(state.computeTarget().asMmolL.formatted(.number.grouping(.never).rounded().precision(.fractionLength(1)))) mmol/L" :
|
|
|
+ "\(state.computeTarget().formatted(.number.grouping(.never).rounded().precision(.fractionLength(0)))) mg/dl"
|
|
|
+ )
|
|
|
+ + NSLocalizedString(" Target Glucose", comment: "")
|
|
|
+ )
|
|
|
+ .foregroundColor(.green)
|
|
|
+ .padding(.vertical)
|
|
|
Slider(
|
|
|
value: $state.hbt,
|
|
|
in: 101 ... 295,
|
|
|
step: 1
|
|
|
).accentColor(.green)
|
|
|
-
|
|
|
- HStack {
|
|
|
- Text(
|
|
|
- (
|
|
|
- state
|
|
|
- .units == .mmolL ?
|
|
|
- "\(state.computeTarget().asMmolL.formatted(.number.grouping(.never).rounded().precision(.fractionLength(1)))) mmol/L" :
|
|
|
- "\(state.computeTarget().formatted(.number.grouping(.never).rounded().precision(.fractionLength(0)))) mg/dl"
|
|
|
- )
|
|
|
- + NSLocalizedString(" Target Glucose", comment: "")
|
|
|
- )
|
|
|
- .foregroundColor(.green)
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -165,7 +161,6 @@ extension AddTempTarget {
|
|
|
.disabled(state.duration == 0)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
Section {
|
|
|
Button { state.enact() }
|
|
|
label: { Text("Enact") }
|
|
|
@@ -225,42 +220,53 @@ extension AddTempTarget {
|
|
|
Section {
|
|
|
Button("Save") {
|
|
|
guard let selectedPreset = selectedPreset else { return }
|
|
|
- state.updatePreset(
|
|
|
- selectedPreset,
|
|
|
- low: state.low
|
|
|
- )
|
|
|
+ state.updatePreset(selectedPreset, low: state.low)
|
|
|
isEditSheetPresented = false
|
|
|
}
|
|
|
.disabled(state.newPresetName.isEmpty)
|
|
|
|
|
|
Button("Cancel") {
|
|
|
+ // Reset the fields and close the sheet
|
|
|
+ resetFields()
|
|
|
isEditSheetPresented = false
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ .onDisappear {
|
|
|
+ if isEditSheetPresented == false {
|
|
|
+ resetFields()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func resetFields() {
|
|
|
+ state.newPresetName = ""
|
|
|
+ state.low = 0
|
|
|
+ state.duration = 0
|
|
|
+ state.percentage = 100 // Reset experimental slider if necessary
|
|
|
}
|
|
|
|
|
|
private func presetView(for preset: TempTarget) -> some View {
|
|
|
var low = preset.targetBottom
|
|
|
- var high = preset.targetBottom // change to only use targetBottom instead of targetTop
|
|
|
if state.units == .mmolL {
|
|
|
low = low?.asMmolL
|
|
|
- high = high?.asMmolL
|
|
|
}
|
|
|
+
|
|
|
return HStack {
|
|
|
VStack {
|
|
|
HStack {
|
|
|
Text(preset.displayName)
|
|
|
Spacer()
|
|
|
- Button {
|
|
|
- selectedPreset = preset
|
|
|
- state.newPresetName = preset.displayName
|
|
|
- state.low = state.units == .mmolL ? preset.targetBottom?
|
|
|
- .asMmolL ?? 0 : preset.targetBottom ?? 0
|
|
|
- state.duration = preset.duration
|
|
|
- state.date = preset.date as? Date ?? Date()
|
|
|
- isEditSheetPresented = true
|
|
|
- } label: {}
|
|
|
+ /* Button {
|
|
|
+ selectedPreset = preset
|
|
|
+ state.newPresetName = preset.displayName
|
|
|
+ state.low = state.units == .mmolL ? preset.targetBottom?.asMmolL ?? 0 : preset.targetBottom ?? 0
|
|
|
+ state.duration = preset.duration
|
|
|
+ state.date = preset.date as? Date ?? Date()
|
|
|
+ isEditSheetPresented = true
|
|
|
+ } label: {
|
|
|
+ Image(systemName: "square.and.pencil")
|
|
|
+ } */
|
|
|
}
|
|
|
HStack(spacing: 2) {
|
|
|
if let lowValue = low,
|
|
|
@@ -292,6 +298,5 @@ extension AddTempTarget {
|
|
|
state.enactPreset(id: preset.id)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
+ } }
|
|
|
}
|