mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
* Add SwiftUI previews for simple helper views Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for action buttons, ChannelForm, MetricsColumnDetail, and DeviceOnboarding Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for config views, log views, AppLog, Firmware, AppData, and UserConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add preview for PositionConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Fix formatting bugs in #Preview blocks: restore missing .environmentObject/.environment modifiers and add proper tab indentation Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/7eeb7a54-7928-466f-8e39-b00d0012a09d Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Linting fixes --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
65 lines
1.6 KiB
Swift
65 lines
1.6 KiB
Swift
//
|
||
// UpdateIntervalPicker.swift
|
||
// Meshtastic
|
||
//
|
||
// Copyright(c) Garth Vander Houwen 10/4/25.
|
||
//
|
||
import SwiftUI
|
||
|
||
struct UpdateIntervalPicker: View {
|
||
let config: IntervalConfiguration
|
||
let pickerLabel: String
|
||
let formatter: DateComponentsFormatter // Make it a stored property
|
||
|
||
@Binding var selectedInterval: UpdateInterval
|
||
|
||
private var fixedOptions: [UpdateInterval] {
|
||
config.allowedCases
|
||
.map { UpdateInterval(from: $0.rawValue) }
|
||
}
|
||
|
||
init(config: IntervalConfiguration, pickerLabel: String, selectedInterval: Binding<UpdateInterval>) {
|
||
self.config = config
|
||
self.pickerLabel = pickerLabel
|
||
self._selectedInterval = selectedInterval
|
||
let f = DateComponentsFormatter()
|
||
f.unitsStyle = .full
|
||
self.formatter = f
|
||
}
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
Picker(pickerLabel, selection: $selectedInterval) {
|
||
ForEach(fixedOptions, id: \.self) { interval in
|
||
Text(interval.description)
|
||
.tag(interval)
|
||
}
|
||
}
|
||
|
||
if isOutOfRange {
|
||
let interval: TimeInterval = Double(selectedInterval.intValue)
|
||
if let formattedString = formatter.string(from: interval) {
|
||
Text("⚠️ The configured value: (\(formattedString)) is not one of the optimized options.")
|
||
.font(.caption)
|
||
.foregroundColor(.orange)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
private var isOutOfRange: Bool {
|
||
switch selectedInterval.type {
|
||
case .manual:
|
||
return true
|
||
case .fixed(let fixedCase):
|
||
return !config.allowedCases.contains(fixedCase)
|
||
}
|
||
}
|
||
}
|
||
|
||
#Preview {
|
||
UpdateIntervalPicker(
|
||
config: .broadcastShort,
|
||
pickerLabel: "Update Interval",
|
||
selectedInterval: .constant(UpdateInterval(from: 30))
|
||
)
|
||
}
|