Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/BarUI/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ struct ContentView: View {
OverviewView(overview: archive.overview, archiveFailure: archive.failure)
case .barApp(let app):
BarAppPageView(app: app, status: monitor.status(of: app), home: Self.home, remote: remote, skipped: archive.overview?.skippedRecords[app], history: archive.history, overview: archive.overview)
case .archive:
case .archive(.events):
ResetsAndPerksPageView(overview: archive.overview, archiveFailure: archive.failure)
case .archive(.imports):
PlaceholderPageView(item: item)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/BarUI/OverviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct OverviewView: View {
}
}

private struct ProblemLabel: View {
struct ProblemLabel: View {
let problem: String

var body: some View {
Expand Down
56 changes: 56 additions & 0 deletions Sources/BarUI/ResetsAndPerksPageView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import BarUICore
import SwiftUI

/// Every reset, Perk change and Tracking change in the Archive. The Overview
/// shows the same section for its range; this page opens on All time so
/// nothing older is out of reach.
struct ResetsAndPerksPageView: View {
/// Nil when the Archive couldn't be opened; `archiveFailure` says why.
let overview: LimitsOverview?
let archiveFailure: String?

@State private var range: TimeRange = .all
/// Who this view is to the overview, which reads as far back as the
/// longest range any view shows.
@State private var viewer = UUID()

var body: some View {
Group {
if let overview {
TimelineView(.periodic(from: .now, by: 30)) { context in
ScrollView {
VStack(alignment: .leading, spacing: 20) {
// A failed read keeps the last events, so without
// this a short history would pass for the whole Archive.
if let problem = overview.problem {
ProblemLabel(problem: problem)
}
ResetsAndPerksSection(
events: overview.events(range: range, now: context.date),
range: range,
now: context.date,
tokensDomain: nil,
rangeSelection: $range
)
}
.padding(.horizontal, 32)
.padding(.vertical, 16)
}
}
.task(id: range) {
await overview.show(range, by: viewer)
}
.onDisappear {
overview.stopShowing(by: viewer)
}
} else {
ContentUnavailableView(
"The Archive couldn't be opened",
systemImage: "externaldrive.badge.exclamationmark",
description: Text(archiveFailure ?? "")
)
}
}
.navigationTitle(ArchivePage.events.title)
}
}
13 changes: 13 additions & 0 deletions Sources/BarUI/ResetsAndPerksSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ struct ResetsAndPerksSection: View {
let now: Date
/// The Tokens chart's span, so this chart's days sit under the same days.
let tokensDomain: ClosedRange<Date>?
/// The page's own range control; nil on the Overview, where the Tokens
/// chart's control drives both sections.
var rangeSelection: Binding<TimeRange>?

/// Off by default: a 5-hour session resets several times a day, and those
/// rows would bury the weekly resets and everything else.
Expand All @@ -27,6 +30,16 @@ struct ResetsAndPerksSection: View {
Text("Resets & Perks")
.font(.headline)
Spacer()
if let rangeSelection {
Picker("Range", selection: rangeSelection) {
ForEach(TimeRange.allCases) { range in
Text(range.label).tag(range)
}
}
.pickerStyle(.segmented)
.labelsHidden()
.fixedSize()
}
Toggle("Show session resets", isOn: $showSessionResets)
.toggleStyle(.switch)
.controlSize(.small)
Expand Down
Loading