Files
rzen aaffa3771c Add iPhone target with shared data layer and persistent cache
Two-target restructure: shared sources (models, services, settings,
extensions, team logos) move into Shared/, consumed by both the
existing macOS menu bar app and a new iOS app. MainService no longer
imports AppKit — platform code attaches via a MainServiceObserver
protocol (MacObserverAdapter wires back to MenuManager / StatusItemManager
/ NotificationManager).

iPhone app is a single SwiftUI page mirroring the macOS menu (playoff
round + yesterday/today/tomorrow), with a gear-icon settings sheet
(display option + IndieAbout for license/changelog). Persistent JSON
snapshot in Application Support paints last-known data on cold launch;
"Updated …" header escalates secondary → orange (>5min) → red (>30min)
so staleness is visually unmistakable. Foreground polling, scenePhase
refresh, and pull-to-refresh; no notifications on iOS in v1.
2026-04-25 06:34:36 -04:00

82 lines
2.6 KiB
Swift

//
// UpdatedHeader.swift
// IceGlass-iOS
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
/// "Updated 2 min ago" + "as of Apr 24, 4:32 PM ET" header.
/// Color escalates as data ages: secondary orange (>5min) red (>30min or never).
/// Self-refreshes every 30s via TimelineView so the relative label stays current
/// without a network call.
struct UpdatedHeader: View {
let lastUpdated: Date?
let isRefreshing: Bool
var body: some View {
TimelineView(.periodic(from: .now, by: 30)) { context in
HStack(alignment: .firstTextBaseline, spacing: 8) {
VStack(alignment: .leading, spacing: 2) {
Text(relativeLabel(now: context.date))
.font(.subheadline)
.fontWeight(.medium)
if let absolute = absoluteLabel() {
Text(absolute)
.font(.caption)
.foregroundStyle(.tertiary)
}
}
.foregroundStyle(staleness(now: context.date).color)
if isRefreshing {
ProgressView()
.controlSize(.small)
}
Spacer()
}
}
}
private enum Staleness {
case fresh
case warm // >5 min
case stale // >30 min or no data
var color: Color {
switch self {
case .fresh: return .secondary
case .warm: return .orange
case .stale: return .red
}
}
}
private func staleness(now: Date) -> Staleness {
guard let lastUpdated else { return .stale }
let age = now.timeIntervalSince(lastUpdated)
if age > 30 * 60 { return .stale }
if age > 5 * 60 { return .warm }
return .fresh
}
private func relativeLabel(now: Date) -> String {
guard let lastUpdated else { return "Never updated" }
let age = now.timeIntervalSince(lastUpdated)
if age < 60 { return "Updated just now" }
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .abbreviated
return "Updated \(formatter.localizedString(for: lastUpdated, relativeTo: now))"
}
private func absoluteLabel() -> String? {
guard let lastUpdated else { return nil }
let formatter = DateFormatter()
formatter.dateFormat = "MMM d, h:mm a"
formatter.timeZone = TimeZone(identifier: "America/New_York")
let stamp = formatter.string(from: lastUpdated)
return "as of \(stamp) ET"
}
}