Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework glucose dialog #139

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension DataTable {
@Published var mode: Mode = .treatments
@Published var treatments: [Treatment] = []
@Published var glucose: [Glucose] = []
@Published var manualGlcuose: Decimal = 0
@Published var manualGlucose: Decimal = 0
@Published var maxBolus: Decimal = 0
@Published var externalInsulinAmount: Decimal = 0
@Published var externalInsulinDate = Date()
Expand Down Expand Up @@ -176,7 +176,7 @@ extension DataTable {
}

func addManualGlucose() {
let glucose = units == .mmolL ? manualGlcuose.asMgdL : manualGlcuose
let glucose = units == .mmolL ? manualGlucose.asMgdL : manualGlucose
let now = Date()
let id = UUID().uuidString

Expand Down
102 changes: 67 additions & 35 deletions FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension DataTable {
@State private var removeCarbsAlert: Alert?
@State private var isRemoveInsulinAlertPresented = false
@State private var removeInsulinAlert: Alert?
@State private var newGlucose = false
@State private var showManualGlucose = false
@State private var showExternalInsulin = false
@State private var isAmountUnconfirmed = true

Expand Down Expand Up @@ -74,34 +74,8 @@ extension DataTable {
}) {
addExternalInsulinView
}
.popup(isPresented: newGlucose, alignment: .top, direction: .bottom) {
VStack(spacing: 20) {
HStack {
Text("New Glucose")
DecimalTextField(" ... ", value: $state.manualGlcuose, formatter: glucoseFormatter)
Text(state.units.rawValue)
}.padding(.horizontal, 20)
HStack {
let limitLow: Decimal = state.units == .mmolL ? 2.2 : 40
let limitHigh: Decimal = state.units == .mmolL ? 21 : 380
Button { newGlucose = false }
label: { Text("Cancel") }.frame(maxWidth: .infinity, alignment: .leading)

Button {
state.addManualGlucose()
newGlucose = false
}
label: { Text("Save") }
.frame(maxWidth: .infinity, alignment: .trailing)
// .disabled(state.manualGlcuose < limitLow || state.manualGlcuose > limitHigh)

}.padding(20)
}
.frame(maxHeight: 140)
.background(
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(Color(colorScheme == .dark ? UIColor.systemGray2 : UIColor.systemGray6))
)
.sheet(isPresented: $showManualGlucose) {
addGlucoseView
}
}

Expand Down Expand Up @@ -137,13 +111,71 @@ extension DataTable {

private var glucoseList: some View {
List {
Button { newGlucose = true }
label: { Text("Add") }.frame(maxWidth: .infinity, alignment: .trailing)
.padding(.trailing, 20)
HStack {
Text("Time").foregroundStyle(.secondary)
Spacer()
Text(state.units.rawValue).foregroundStyle(.secondary)
Button(
action: {
showManualGlucose = true
state.manualGlucose = 0
},
label: { Image(systemName: "plus.circle.fill").foregroundStyle(.secondary)
}
).buttonStyle(.borderless)
}
if !state.glucose.isEmpty {
ForEach(state.glucose) { item in
glucoseView(item)
}
.onDelete(perform: deleteGlucose)
} else {
HStack {
Text(NSLocalizedString("No data.", comment: "No data text when no entries in history list"))
}
}
}
}

private var addGlucoseView: some View {
NavigationView {
VStack {
Form {
Section {
HStack {
Text("New Glucose")
DecimalTextField(
" ... ",
value: $state.manualGlucose,
formatter: glucoseFormatter,
autofocus: true,
cleanInput: true
)
Text(state.units.rawValue).foregroundStyle(.secondary)
}
}

Section {
HStack {
let limitLow: Decimal = state.units == .mmolL ? 0.8 : 40
let limitHigh: Decimal = state.units == .mmolL ? 14 : 720

ForEach(state.glucose) { item in
glucoseView(item)
}.onDelete(perform: deleteGlucose)
Button {
state.addManualGlucose()
isAmountUnconfirmed = false
showManualGlucose = false
}
label: { Text("Save") }
.frame(maxWidth: .infinity, alignment: .center)
.disabled(state.manualGlucose < limitLow || state.manualGlucose > limitHigh)
}
}
}
}
.onAppear(perform: configureView)
.navigationTitle("Add Glucose")
.navigationBarTitleDisplayMode(.automatic)
.navigationBarItems(leading: Button("Close", action: { showManualGlucose = false }))
}
}

Expand Down