summaryrefslogtreecommitdiff
path: root/Hutch/Views/Home/HomeViewModel.swift
diff options
context:
space:
mode:
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 }