Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
119 lines
3.7 KiB
Swift
Executable File
119 lines
3.7 KiB
Swift
Executable File
// StateViews — the three async-phase views every screen needs (loading /
|
|
// failed / empty), extracted from the shapes LikesView established so all
|
|
// screens fail and idle identically. Screens keep their own Phase enums;
|
|
// these are just the bodies.
|
|
|
|
import Inject
|
|
import RedWhiteUI
|
|
import SwiftUI
|
|
|
|
// MARK: - LoadingView
|
|
|
|
/// Centered red-tinted spinner. Fills the available space so it centers in
|
|
/// whatever region the screen gives the loading phase.
|
|
public struct LoadingView: View {
|
|
// The active RedWhiteUI palette (set once by AppRoot's .rwTheme()).
|
|
@Environment(\.rw) private var p
|
|
|
|
public init() {}
|
|
|
|
@ObserveInjection var inject
|
|
|
|
public var body: some View {
|
|
ProgressView()
|
|
// .color, not the RwColor ShapeStyle: ProgressView only honors the
|
|
// Color overload of .tint.
|
|
.tint(p.red.color)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.enableInjection()
|
|
}
|
|
}
|
|
|
|
// MARK: - ErrorStateView
|
|
|
|
/// Load-failure state with an optional Retry. The message is the error's own
|
|
/// localizedDescription (screens pass it straight through — the API layer
|
|
/// already produces human-readable messages).
|
|
public struct ErrorStateView: View {
|
|
// The active RedWhiteUI palette (set once by AppRoot's .rwTheme()).
|
|
@Environment(\.rw) private var p
|
|
|
|
private let message: String
|
|
private let retry: (() -> Void)?
|
|
|
|
public init(message: String, retry: (() -> Void)? = nil) {
|
|
self.message = message
|
|
self.retry = retry
|
|
}
|
|
|
|
@ObserveInjection var inject
|
|
|
|
public var body: some View {
|
|
VStack(spacing: RwSizes.gap) {
|
|
// Icons use iconInactive, not textMuted (gray reads off-brand on chrome).
|
|
Image(systemName: "exclamationmark.triangle")
|
|
.font(.system(size: 36))
|
|
.foregroundStyle(p.iconInactive)
|
|
// .rw() bakes its color in — a chained .foregroundStyle would be
|
|
// ignored, so the color rides along as the parameter.
|
|
Text("Something went wrong")
|
|
.rw(.titleLarge, color: p.text.color)
|
|
Text(message)
|
|
.rw(.bodySmall)
|
|
.multilineTextAlignment(.center)
|
|
if let retry {
|
|
// The house button (page-colored, red hairline, inverts on press)
|
|
// replaces the old hand-rolled solid-red pill.
|
|
Button("Retry", action: retry)
|
|
.buttonStyle(.bare)
|
|
}
|
|
}
|
|
.padding(RwSizes.pagePadding)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.enableInjection()
|
|
}
|
|
}
|
|
|
|
// MARK: - EmptyStateView
|
|
|
|
/// Legitimately-empty state ("No likes yet") — visually distinct from failure
|
|
/// so users don't retry something that worked fine.
|
|
public struct EmptyStateView: View {
|
|
// The active RedWhiteUI palette (set once by AppRoot's .rwTheme()).
|
|
@Environment(\.rw) private var p
|
|
|
|
private let icon: String
|
|
private let title: String
|
|
private let message: String?
|
|
|
|
/// `icon` is an SF Symbol name (e.g. "heart", "magnifyingglass").
|
|
public init(icon: String, title: String, message: String? = nil) {
|
|
self.icon = icon
|
|
self.title = title
|
|
self.message = message
|
|
}
|
|
|
|
@ObserveInjection var inject
|
|
|
|
public var body: some View {
|
|
VStack(spacing: RwSizes.gap) {
|
|
// Icons use iconInactive, not textMuted (gray reads off-brand on chrome).
|
|
Image(systemName: icon)
|
|
.font(.system(size: 36))
|
|
.foregroundStyle(p.iconInactive)
|
|
// .rw() bakes its color in — a chained .foregroundStyle would be
|
|
// ignored, so the color rides along as the parameter.
|
|
Text(title)
|
|
.rw(.titleLarge, color: p.text.color)
|
|
if let message {
|
|
Text(message)
|
|
.rw(.bodySmall)
|
|
.multilineTextAlignment(.center)
|
|
}
|
|
}
|
|
.padding(RwSizes.pagePadding)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.enableInjection()
|
|
}
|
|
}
|