Improve route statistics
This commit is contained in:
@ -3,6 +3,9 @@ import SFSafeSymbols
|
||||
|
||||
struct InsertableRoute: View, InsertableCommandView {
|
||||
|
||||
@Environment(\.language)
|
||||
var language
|
||||
|
||||
final class Model: ObservableObject, InsertableCommandModel {
|
||||
|
||||
@Published
|
||||
@ -12,7 +15,7 @@ struct InsertableRoute: View, InsertableCommandView {
|
||||
var chartTitle: String?
|
||||
|
||||
@Published
|
||||
var components: RouteViewComponents = .all
|
||||
var components: Set<RouteStatisticType> = Set(RouteStatisticType.allCases)
|
||||
|
||||
@Published
|
||||
var mapTitle: String?
|
||||
@ -39,7 +42,12 @@ struct InsertableRoute: View, InsertableCommandView {
|
||||
var result = ["```route"]
|
||||
result.append("\(RouteBlock.Key.image.rawValue): \(selectedImage.id)")
|
||||
result.append("\(RouteBlock.Key.file.rawValue): \(dataFile.id)")
|
||||
result.append("\(RouteBlock.Key.components.rawValue): \(components.rawValue)")
|
||||
if components != Set(RouteStatisticType.allCases) {
|
||||
let list = components
|
||||
.map { $0.rawValue }
|
||||
.joined(separator: ", ")
|
||||
result.append("\(RouteBlock.Key.components.rawValue): \(list)")
|
||||
}
|
||||
if let caption {
|
||||
result.append("\(RouteBlock.Key.caption.rawValue): \(caption)")
|
||||
}
|
||||
@ -94,14 +102,22 @@ struct InsertableRoute: View, InsertableCommandView {
|
||||
text: $model.chartTitle,
|
||||
prompt: "Title",
|
||||
footer: "The title to show above the statistics")
|
||||
Picker(selection: $model.components) {
|
||||
Text("All").tag(RouteViewComponents.all)
|
||||
Text("Only elevation").tag(RouteViewComponents.withoutHeartRate)
|
||||
Text("No heart rate").tag(RouteViewComponents.withoutHeartRate)
|
||||
} label: {
|
||||
Text("")
|
||||
ForEach(RouteStatisticType.allCases.sorted(), id: \.rawValue) { type in
|
||||
Toggle(isOn: Binding(
|
||||
get: {
|
||||
model.components.contains(type)
|
||||
},
|
||||
set: { isSelected in
|
||||
if isSelected {
|
||||
model.components.insert(type)
|
||||
} else {
|
||||
model.components.remove(type)
|
||||
}
|
||||
}
|
||||
)) {
|
||||
Text(type.displayText(in: language))
|
||||
}.toggleStyle(.checkbox)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user