import Foundation import Observation /// The web dashboard contract — attention queues, open work, pins, and /// recent activity — in one `dashboard` read. This replaced a per-repo fan-out that /// drained the rate bucket at 64 of 66 repos; krz/gitbay#41 added the /// aggregate. @Observable @MainActor final class DashboardViewModel { private(set) var state: LoadState = .loading private let client: GitbayClient init(client: GitbayClient) { self.client = client } func load() async { do { let data = try await client.read(["dashboard"], as: DashboardData.self) state = .loaded(data) // The authoritative resync. A push sets the badge on arrival // and nothing lowers it afterwards, so this is what corrects // it — on every app open, against the account you are in. await setAppBadge(data.unread) } catch { state = .from(error) } } }