-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistoryView.swift
More file actions
63 lines (56 loc) · 1.84 KB
/
Copy pathHistoryView.swift
File metadata and controls
63 lines (56 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import SwiftUI
struct HistoryView: View {
@EnvironmentObject var runManager: RunManager
var body: some View {
NavigationStack {
Group {
if runManager.history.isEmpty {
ContentUnavailableView(
"No Runs Yet",
systemImage: "figure.run",
description: Text("Your completed runs will appear here.")
)
} else {
List {
ForEach(runManager.history) { run in
RunRow(run: run)
}
.onDelete(perform: runManager.deleteRuns)
}
}
}
.navigationTitle("History")
}
}
}
private struct RunRow: View {
let run: Run
private static let dateFormatter: DateFormatter = {
let f = DateFormatter()
f.dateStyle = .medium
f.timeStyle = .short
return f
}()
var body: some View {
VStack(alignment: .leading, spacing: 6) {
Text(Self.dateFormatter.string(from: run.date))
.font(.subheadline)
.foregroundStyle(.secondary)
HStack(spacing: 24) {
stat(value: run.formattedDuration, label: "time")
stat(value: run.formattedDistance, label: "distance")
stat(value: run.formattedPace, label: "pace")
}
}
.padding(.vertical, 4)
}
private func stat(value: String, label: String) -> some View {
VStack(alignment: .leading, spacing: 1) {
Text(value)
.font(.system(.body, design: .monospaced).weight(.medium))
Text(label)
.font(.caption2)
.foregroundStyle(.secondary)
}
}
}