Files
yattee/Yattee/Views/Components/AccountStatusBadge.swift
Arkadiusz Fal e661635079 Let every menu mark the current context and a disabled source admit it
MAC1: switcher rows are Toggles on macOS so the checkmark really renders,
and the settings row names its context via LabeledContent with a tooltip.
MAC4: accessible names are words, never raw SF Symbol identifiers.
MAC14: new displayStatus(for:) surfaces instanceDisabled on account rows,
badges, and the switcher tooltip without disturbing status(for:) consumers.
MAC16: disambiguated labels guard the username branch and fall back to the
source name only when rows would still collide.
Also carries the new Localizable strings for the whole macOS fix batch.
2026-09-11 08:02:26 +02:00

52 lines
1.9 KiB
Swift

//
// AccountStatusBadge.swift
// Yattee
//
// How an account's status reads, wherever accounts are listed.
//
import SwiftUI
/// An account's status as one line of caption text.
///
/// Shared so a status says the same thing in every list it appears in — the
/// per-instance section, the accounts screen and the context switcher all name
/// the same states, and one added to `AccountStatus` is named once rather than
/// three times.
struct AccountStatusBadge: View {
let status: AccountStatus
var body: some View {
Text(Self.text(for: status))
.font(.caption)
.foregroundStyle(Self.color(for: status))
}
static func text(for status: AccountStatus) -> String {
switch status {
case .checking: String(localized: "accounts.status.checking")
case .signedIn: String(localized: "accounts.status.signedIn")
case .credentialMissing: String(localized: "accounts.status.credentialMissing")
case .credentialRejected: String(localized: "accounts.status.credentialRejected")
case .instanceDisabled: String(localized: "accounts.status.instanceDisabled")
case .unreachable: String(localized: "accounts.status.unreachable")
}
}
/// Only the states the user has to act on are coloured. A credential that
/// never arrived on this device is ordinary — tvOS never receives them at
/// all — so it reads as secondary rather than as a fault. A switched-off
/// source is the user's own doing, and the banner already reads it as
/// grey.
static func color(for status: AccountStatus) -> Color {
switch status {
case .checking: .secondary
case .signedIn: .secondary
case .credentialMissing: .secondary
case .credentialRejected: .red
case .instanceDisabled: .secondary
case .unreachable: .orange
}
}
}