summaryrefslogtreecommitdiff
path: root/Hutch/Views/Home/HomeViewModel.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-11 23:36:35 -0500
committerChristian Cleberg <[email protected]>2026-04-11 23:36:35 -0500
commit00cc231e9b419d27b412036d93457c2cbabe0b16 (patch)
tree6b042b802fcddcd1e03f1ae0f666965620225485 /Hutch/Views/Home/HomeViewModel.swift
parent0fde7529ceaebf1cd9baa01826d95d587023d001 (diff)
downloadhutch-00cc231e9b419d27b412036d93457c2cbabe0b16.tar.gz
hutch-00cc231e9b419d27b412036d93457c2cbabe0b16.tar.bz2
hutch-00cc231e9b419d27b412036d93457c2cbabe0b16.zip
Add SourceHut system status screen and home disruption banner
Diffstat (limited to 'Hutch/Views/Home/HomeViewModel.swift')
-rw-r--r--Hutch/Views/Home/HomeViewModel.swift20
1 files changed, 19 insertions, 1 deletions
diff --git a/Hutch/Views/Home/HomeViewModel.swift b/Hutch/Views/Home/HomeViewModel.swift
index 8b4e7aa..a06df20 100644
--- a/Hutch/Views/Home/HomeViewModel.swift
+++ b/Hutch/Views/Home/HomeViewModel.swift
@@ -143,6 +143,7 @@ final class HomeViewModel {
private(set) var projects: [Project] = []
var assignedTickets: [HomeAssignedTicket] = []
var recentBuilds: [HomeBuildItem] = []
+ private(set) var systemStatusSnapshot: SystemStatusSnapshot?
private(set) var hasUnreadInboxThreads = false
private(set) var unreadInboxThreadCount: Int?
private(set) var isLoadingProjects = false
@@ -153,6 +154,7 @@ final class HomeViewModel {
private let currentUser: User
private let client: SRHTClient
+ private let systemStatusRepository: SystemStatusRepository
private let projectService: ProjectService
private let ticketFetchConcurrencyLimit = 6
private let inboxUnreadConcurrencyLimit = 4
@@ -266,9 +268,10 @@ final class HomeViewModel {
}
"""
- init(currentUser: User, client: SRHTClient) {
+ init(currentUser: User, client: SRHTClient, systemStatusRepository: SystemStatusRepository) {
self.currentUser = currentUser
self.client = client
+ self.systemStatusRepository = systemStatusRepository
self.projectService = ProjectService(client: client)
}
@@ -283,6 +286,7 @@ final class HomeViewModel {
async let jobsTask = loadRecentJobs()
async let assignedTicketsTask = loadAssignedTickets()
async let inboxUnreadTask = loadInboxUnreadCount()
+ async let systemStatusTask = loadSystemStatusSnapshot()
let projectsResult = await projectsTask
switch projectsResult {
@@ -320,9 +324,15 @@ final class HomeViewModel {
unreadInboxThreadCount = await inboxUnreadTask
hasUnreadInboxThreads = (unreadInboxThreadCount ?? 0) > 0
+ systemStatusSnapshot = await systemStatusTask
persistNeedsAttentionSnapshot()
}
+ var systemStatusBannerTitle: String? {
+ guard let systemStatusSnapshot, systemStatusSnapshot.hasDisruption else { return nil }
+ return systemStatusSnapshot.bannerSummary
+ }
+
func resolveTicket(_ ticket: HomeAssignedTicket) async {
let input: [String: any Sendable] = [
"status": TicketStatus.resolved.rawValue,
@@ -420,6 +430,14 @@ final class HomeViewModel {
}
}
+ private func loadSystemStatusSnapshot() async -> SystemStatusSnapshot? {
+ do {
+ return try await systemStatusRepository.snapshot()
+ } catch {
+ return systemStatusSnapshot
+ }
+ }
+
private func fetchUnreadInboxThreadCount() async throws -> Int {
let mailingLists = try await fetchInboxMailingLists()
guard !mailingLists.isEmpty else { return 0 }