| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import SwiftUI
- struct NightscoutUploadView: View {
- @ObservedObject var state: NightscoutConfig.StateModel
- @State private var shouldDisplayHint: Bool = false
- @State var hintDetent = PresentationDetent.large
- @State var selectedVerboseHint: AnyView?
- @State var hintLabel: String?
- @State private var decimalPlaceholder: Decimal = 0.0
- @State private var booleanPlaceholder: Bool = false
- @Environment(\.colorScheme) var colorScheme
- var color: LinearGradient {
- colorScheme == .dark ? LinearGradient(
- gradient: Gradient(colors: [
- Color.bgDarkBlue,
- Color.bgDarkerDarkBlue
- ]),
- startPoint: .top,
- endPoint: .bottom
- )
- :
- LinearGradient(
- gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
- startPoint: .top,
- endPoint: .bottom
- )
- }
- var body: some View {
- Form {
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.isUploadEnabled,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0.map { AnyView($0) }
- hintLabel = "Allow Uploading to Nightscout"
- shouldDisplayHint = true
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Allow Uploading to Nightscout",
- miniHint: "Enables upload of selected data sets to Nightscout. See hint for more details.",
- verboseHint: Text(
- "The Upload Treatments toggle enables uploading of carbs, temp targets, device status, preferences and settings."
- )
- )
- if state.changeUploadGlucose {
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.uploadGlucose,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0.map { AnyView($0) }
- hintLabel = "Upload Glucose"
- shouldDisplayHint = true
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Upload Glucose",
- miniHint: "Enables uploading of CGM readings to Nightscout.",
- verboseHint: Text("Write stuff here.")
- )
- }
- }
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? AnyView(EmptyView()),
- sheetTitle: "Help"
- )
- }
- .navigationTitle("Upload")
- .navigationBarTitleDisplayMode(.automatic)
- .scrollContentBackground(.hidden).background(color)
- }
- }
|