|
|
@@ -22,9 +22,19 @@ extension BasalProfileEditor {
|
|
|
Form {
|
|
|
Section(header: Text("Schedule")) {
|
|
|
List {
|
|
|
- ForEach(viewModel.items.indexed(), id: \.1.id) { index, _ in
|
|
|
+ ForEach(viewModel.items.indexed(), id: \.1.id) { index, item in
|
|
|
NavigationLink(destination: pickers(for: index)) {
|
|
|
- Text("text")
|
|
|
+ HStack {
|
|
|
+ Text("Rate").foregroundColor(.secondary)
|
|
|
+ Text(
|
|
|
+ "\(rateFormatter.string(from: viewModel.rateValues[item.rateIndex] as NSNumber) ?? "0") U/h"
|
|
|
+ )
|
|
|
+ Spacer()
|
|
|
+ Text("starts at").foregroundColor(.secondary)
|
|
|
+ Text(
|
|
|
+ "\(dateFormatter.string(from: Date(timeIntervalSince1970: viewModel.timeValues[item.timeIndex])))"
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
.moveDisabled(true)
|
|
|
}
|
|
|
@@ -37,7 +47,7 @@ extension BasalProfileEditor {
|
|
|
label: {
|
|
|
Text(viewModel.syncInProgress ? "Saving..." : "Save on Pump")
|
|
|
}
|
|
|
- .disabled(viewModel.syncInProgress)
|
|
|
+ .disabled(viewModel.syncInProgress || viewModel.items.isEmpty)
|
|
|
}
|
|
|
}
|
|
|
.navigationTitle("Basal Profile")
|
|
|
@@ -47,38 +57,40 @@ extension BasalProfileEditor {
|
|
|
trailing: EditButton()
|
|
|
)
|
|
|
.environment(\.editMode, $editMode)
|
|
|
+ .onAppear {
|
|
|
+ viewModel.validate()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private func pickers(for index: Int) -> some View {
|
|
|
GeometryReader { geometry in
|
|
|
VStack {
|
|
|
HStack {
|
|
|
- Text("Time").frame(width: geometry.size.width / 2)
|
|
|
Text("Rate").frame(width: geometry.size.width / 2)
|
|
|
+ Text("Time").frame(width: geometry.size.width / 2)
|
|
|
}
|
|
|
HStack(spacing: 0) {
|
|
|
- Picker(selection: $viewModel.items[index].timeIndex, label: EmptyView()) {
|
|
|
- ForEach(0 ..< viewModel.timeValues.count, id: \.self) { i in
|
|
|
+ Picker(selection: $viewModel.items[index].rateIndex, label: EmptyView()) {
|
|
|
+ ForEach(0 ..< viewModel.rateValues.count, id: \.self) { i in
|
|
|
Text(
|
|
|
- self.dateFormatter
|
|
|
- .string(from: Date(
|
|
|
- timeIntervalSince1970: viewModel
|
|
|
- .timeValues[i]
|
|
|
- ))
|
|
|
+ (
|
|
|
+ self.rateFormatter
|
|
|
+ .string(from: viewModel.rateValues[i] as NSNumber) ?? ""
|
|
|
+ ) + " U/h"
|
|
|
).tag(i)
|
|
|
}
|
|
|
}
|
|
|
- .disabled(index == 0)
|
|
|
.frame(maxWidth: geometry.size.width / 2)
|
|
|
.clipped()
|
|
|
|
|
|
- Picker(selection: $viewModel.items[index].rateIndex, label: EmptyView()) {
|
|
|
- ForEach(0 ..< viewModel.rateValues.count, id: \.self) { i in
|
|
|
+ Picker(selection: $viewModel.items[index].timeIndex, label: EmptyView()) {
|
|
|
+ ForEach(0 ..< viewModel.timeValues.count, id: \.self) { i in
|
|
|
Text(
|
|
|
- (
|
|
|
- self.rateFormatter
|
|
|
- .string(from: viewModel.rateValues[i] as NSNumber) ?? ""
|
|
|
- ) + " U/h"
|
|
|
+ self.dateFormatter
|
|
|
+ .string(from: Date(
|
|
|
+ timeIntervalSince1970: viewModel
|
|
|
+ .timeValues[i]
|
|
|
+ ))
|
|
|
).tag(i)
|
|
|
}
|
|
|
}
|
|
|
@@ -108,7 +120,7 @@ extension BasalProfileEditor {
|
|
|
|
|
|
private func onDelete(offsets: IndexSet) {
|
|
|
viewModel.items.remove(atOffsets: offsets)
|
|
|
- viewModel.itemsDidChange()
|
|
|
+ viewModel.validate()
|
|
|
}
|
|
|
}
|
|
|
}
|