From cb1ea5ea4f163d87053285d3fb7999b12a3558b9 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Sun, 12 Apr 2026 00:15:13 -0500 Subject: harden system status and app reliability --- Hutch/Views/Home/HomeViewModel.swift | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'Hutch/Views/Home/HomeViewModel.swift') diff --git a/Hutch/Views/Home/HomeViewModel.swift b/Hutch/Views/Home/HomeViewModel.swift index a06df20..ba00a36 100644 --- a/Hutch/Views/Home/HomeViewModel.swift +++ b/Hutch/Views/Home/HomeViewModel.swift @@ -144,6 +144,9 @@ final class HomeViewModel { var assignedTickets: [HomeAssignedTicket] = [] var recentBuilds: [HomeBuildItem] = [] private(set) var systemStatusSnapshot: SystemStatusSnapshot? + private(set) var isLoadingSystemStatus = false + private(set) var isShowingStaleSystemStatus = false + private(set) var systemStatusErrorMessage: String? private(set) var hasUnreadInboxThreads = false private(set) var unreadInboxThreadCount: Int? private(set) var isLoadingProjects = false @@ -279,8 +282,11 @@ final class HomeViewModel { isLoadingProjects = true isLoadingAssignedTickets = true isLoadingRecentBuilds = true + isLoadingSystemStatus = true assignedTicketsError = nil recentBuildsError = nil + isShowingStaleSystemStatus = false + systemStatusErrorMessage = nil async let projectsTask = loadProjects() async let jobsTask = loadRecentJobs() @@ -324,13 +330,21 @@ final class HomeViewModel { unreadInboxThreadCount = await inboxUnreadTask hasUnreadInboxThreads = (unreadInboxThreadCount ?? 0) > 0 - systemStatusSnapshot = await systemStatusTask + let systemStatusResult = await systemStatusTask + switch systemStatusResult { + case .success(let result): + systemStatusSnapshot = result.value + isShowingStaleSystemStatus = result.isStale + systemStatusErrorMessage = result.isStale ? result.refreshErrorMessage : nil + case .failure(let error): + systemStatusErrorMessage = error.userFacingMessage + } + isLoadingSystemStatus = false persistNeedsAttentionSnapshot() } - var systemStatusBannerTitle: String? { - guard let systemStatusSnapshot, systemStatusSnapshot.hasDisruption else { return nil } - return systemStatusSnapshot.bannerSummary + var hasDashboardContent: Bool { + !projects.isEmpty || !assignedTickets.isEmpty || !recentBuilds.isEmpty || systemStatusSnapshot != nil } func resolveTicket(_ ticket: HomeAssignedTicket) async { @@ -430,11 +444,11 @@ final class HomeViewModel { } } - private func loadSystemStatusSnapshot() async -> SystemStatusSnapshot? { + private func loadSystemStatusSnapshot() async -> Result, Error> { do { - return try await systemStatusRepository.snapshot() + return .success(try await systemStatusRepository.snapshotResult()) } catch { - return systemStatusSnapshot + return .failure(error) } } -- cgit v1.2.3