|
|
@@ -7,23 +7,50 @@ import WatchKit
|
|
|
struct BolusInputView: View {
|
|
|
@Environment(\.dismiss) var dismiss
|
|
|
@State private var bolusAmount = 0.0
|
|
|
- @State private var isExternalInsulin = false
|
|
|
@State private var showingConfirmation = false
|
|
|
@State private var confirmationProgress = 0.0
|
|
|
let state: WatchState
|
|
|
|
|
|
var body: some View {
|
|
|
- NavigationView {
|
|
|
+ NavigationStack {
|
|
|
if showingConfirmation {
|
|
|
BolusConfirmationView(
|
|
|
- amount: bolusAmount,
|
|
|
- isExternal: isExternalInsulin,
|
|
|
+ bolusAmount: bolusAmount,
|
|
|
progress: $confirmationProgress,
|
|
|
state: state,
|
|
|
dismiss: dismiss
|
|
|
)
|
|
|
+ .navigationTitle("Confirm")
|
|
|
+ .navigationBarBackButtonHidden(true)
|
|
|
+ .toolbar {
|
|
|
+ ToolbarItem(placement: .topBarLeading) {
|
|
|
+ Button {
|
|
|
+ if state.carbsAmount > 0 {
|
|
|
+ state.carbsAmount = 0
|
|
|
+ }
|
|
|
+ dismiss()
|
|
|
+ } label: {
|
|
|
+ Image(systemName: "xmark")
|
|
|
+ }
|
|
|
+ .buttonStyle(.bordered)
|
|
|
+ .clipShape(Circle())
|
|
|
+ }
|
|
|
+
|
|
|
+ ToolbarItem(placement: .topBarTrailing) {
|
|
|
+ Image(systemName: "digitalcrown.arrow.counterclockwise.fill")
|
|
|
+ .foregroundStyle(Color.white)
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
VStack {
|
|
|
+ if state.carbsAmount > 0 {
|
|
|
+ HStack {
|
|
|
+ Text("Carbs: \(state.carbsAmount) g").font(.subheadline).padding(.bottom)
|
|
|
+ Spacer()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: handle bolus recommendation
|
|
|
Picker("Bolus", selection: $bolusAmount) {
|
|
|
ForEach(0 ... 100, id: \.self) { number in
|
|
|
Text(String(format: "%.1f U", Double(number) / 10))
|
|
|
@@ -31,11 +58,7 @@ struct BolusInputView: View {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Toggle("External Insulin", isOn: $isExternalInsulin)
|
|
|
- .toggleStyle(.switch)
|
|
|
- .padding(.horizontal)
|
|
|
-
|
|
|
- Button(isExternalInsulin ? "Add External Insulin" : "Add Bolus") {
|
|
|
+ Button("Add Bolus") {
|
|
|
showingConfirmation = true
|
|
|
}
|
|
|
.buttonStyle(.bordered)
|
|
|
@@ -48,8 +71,7 @@ struct BolusInputView: View {
|
|
|
}
|
|
|
|
|
|
struct BolusConfirmationView: View {
|
|
|
- let amount: Double
|
|
|
- let isExternal: Bool
|
|
|
+ let bolusAmount: Double
|
|
|
@Binding var progress: Double
|
|
|
let state: WatchState
|
|
|
let dismiss: DismissAction
|
|
|
@@ -58,17 +80,15 @@ struct BolusConfirmationView: View {
|
|
|
|
|
|
var body: some View {
|
|
|
VStack(spacing: 10) {
|
|
|
- Text("Confirm \(isExternal ? "External Insulin" : "Bolus")")
|
|
|
- .font(.headline)
|
|
|
+ if state.carbsAmount > 0 {
|
|
|
+ Text(String(format: "%.1f g", state.carbsAmount))
|
|
|
+ .bold()
|
|
|
+ .foregroundStyle(.orange)
|
|
|
+ }
|
|
|
|
|
|
- Text(String(format: "%.1f U", amount))
|
|
|
- .font(.title2)
|
|
|
+ Text(String(format: "%.1f U", bolusAmount))
|
|
|
.bold()
|
|
|
-
|
|
|
- Text("Scroll crown down\nto confirm")
|
|
|
- .multilineTextAlignment(.center)
|
|
|
- .font(.caption2)
|
|
|
- .foregroundStyle(.secondary)
|
|
|
+ .foregroundStyle(.blue)
|
|
|
|
|
|
ProgressView(value: progress, total: 1.0)
|
|
|
.tint(progress >= 1.0 ? .green : .blue)
|
|
|
@@ -78,7 +98,6 @@ struct BolusConfirmationView: View {
|
|
|
.font(.caption2)
|
|
|
.foregroundStyle(.secondary)
|
|
|
}
|
|
|
- .navigationBarBackButtonHidden(true)
|
|
|
.focusable(true)
|
|
|
.focused($isCrownFocused)
|
|
|
.digitalCrownRotation(
|
|
|
@@ -98,7 +117,11 @@ struct BolusConfirmationView: View {
|
|
|
WKInterfaceDevice.current().play(.success)
|
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
|
- state.sendBolusRequest(Decimal(amount), isExternal: isExternal)
|
|
|
+ if state.carbsAmount > 0 {
|
|
|
+ state.sendCarbsRequest(state.carbsAmount, Date())
|
|
|
+ state.carbsAmount = 0 // reset carbs in state
|
|
|
+ }
|
|
|
+ state.sendBolusRequest(Decimal(bolusAmount))
|
|
|
dismiss()
|
|
|
}
|
|
|
} else if newValue > 0 {
|