diff options
| author | Christian Cleberg <[email protected]> | 2026-04-12 23:19:20 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-12 23:19:20 -0500 |
| commit | ee9f2904aa319231b7047fca3cb069f0c07019cd (patch) | |
| tree | 69a18234512c63f38f0d477e0023969698ec3c9e /Hutch/Views/Home | |
| parent | 72f860e0e171f6aac4e7d896e7a571147dbcb5c5 (diff) | |
| download | hutch-ee9f2904aa319231b7047fca3cb069f0c07019cd.tar.gz hutch-ee9f2904aa319231b7047fca3cb069f0c07019cd.tar.bz2 hutch-ee9f2904aa319231b7047fca3cb069f0c07019cd.zip | |
feat: add multi-account support
Implements: https://todo.sr.ht/~ccleberg/hutch/49
Implements: https://todo.sr.ht/~ccleberg/hutch/50
Implements: https://todo.sr.ht/~ccleberg/hutch/51
Diffstat (limited to 'Hutch/Views/Home')
| -rw-r--r-- | Hutch/Views/Home/HomeView.swift | 8 | ||||
| -rw-r--r-- | Hutch/Views/Home/HomeViewModel.swift | 29 |
2 files changed, 26 insertions, 11 deletions
diff --git a/Hutch/Views/Home/HomeView.swift b/Hutch/Views/Home/HomeView.swift index 426d351..abde827 100644 --- a/Hutch/Views/Home/HomeView.swift +++ b/Hutch/Views/Home/HomeView.swift @@ -1,7 +1,7 @@ import SwiftUI struct HomeView: View { - @AppStorage(AppStorageKeys.swipeActionsEnabled) private var swipeActionsEnabled = true + @AppStorage(AppStorageKeys.swipeActionsEnabled, store: .standard) private var swipeActionsEnabled = true @AppStorage(AppStorageKeys.homeProjectsExpanded) private var projectsExpanded = true @AppStorage(AppStorageKeys.homeAssignedTicketsExpanded) private var assignedTicketsExpanded = true @AppStorage(AppStorageKeys.homeBuildsExpanded) private var buildsExpanded = true @@ -39,7 +39,9 @@ struct HomeView: View { let newViewModel = HomeViewModel( currentUser: currentUser, client: appState.client, - systemStatusRepository: appState.systemStatusRepository + systemStatusRepository: appState.systemStatusRepository, + defaults: appState.accountDefaults, + accountID: appState.activeAccountID ) viewModel = newViewModel vm = newViewModel @@ -834,7 +836,7 @@ private struct HomeAttentionLinkRow<Destination: View>: View { private struct HomeAssignedTicketsListView: View { let viewModel: HomeViewModel - @AppStorage(AppStorageKeys.swipeActionsEnabled) private var swipeActionsEnabled = true + @AppStorage(AppStorageKeys.swipeActionsEnabled, store: .standard) private var swipeActionsEnabled = true var body: some View { List { diff --git a/Hutch/Views/Home/HomeViewModel.swift b/Hutch/Views/Home/HomeViewModel.swift index 682c94d..a28f731 100644 --- a/Hutch/Views/Home/HomeViewModel.swift +++ b/Hutch/Views/Home/HomeViewModel.swift @@ -321,11 +321,22 @@ final class HomeViewModel { } """ - init(currentUser: User, client: SRHTClient, systemStatusRepository: SystemStatusRepository) { + private let defaults: UserDefaults + private let accountID: String + + init( + currentUser: User, + client: SRHTClient, + systemStatusRepository: SystemStatusRepository, + defaults: UserDefaults, + accountID: String + ) { self.currentUser = currentUser self.client = client self.systemStatusRepository = systemStatusRepository self.projectService = ProjectService(client: client) + self.defaults = defaults + self.accountID = accountID } func loadDashboard() async { @@ -403,7 +414,7 @@ final class HomeViewModel { } var pinnedProjects: [Project] { - let pinnedIDs = ProjectPinStore.loadPinnedProjectIDs(for: currentUserKey) + let pinnedIDs = ProjectPinStore.loadPinnedProjectIDs(for: currentUserKey, defaults: defaults) guard !pinnedIDs.isEmpty else { return [] } let projectsByID = Dictionary(uniqueKeysWithValues: projects.map { ($0.id, $0) }) @@ -411,7 +422,7 @@ final class HomeViewModel { } var hasPinnedProjects: Bool { - !ProjectPinStore.loadPinnedProjectIDs(for: currentUserKey).isEmpty + !ProjectPinStore.loadPinnedProjectIDs(for: currentUserKey, defaults: defaults).isEmpty } var failedBuildCount: Int { @@ -592,7 +603,7 @@ final class HomeViewModel { } func markInboxThreadRead(_ thread: InboxThreadSummary) { - InboxReadStateStore.markViewed(max(Date(), thread.lastActivityAt), for: thread.id) + InboxReadStateStore.markViewed(max(Date(), thread.lastActivityAt), for: thread.id, defaults: defaults) unreadInboxThreads.removeAll { $0.id == thread.id } unreadInboxThreadCount = max((unreadInboxThreadCount ?? 1) - 1, 0) hasUnreadInboxThreads = (unreadInboxThreadCount ?? 0) > 0 @@ -600,7 +611,7 @@ final class HomeViewModel { } func markInboxThreadUnread(_ thread: InboxThreadSummary) { - InboxReadStateStore.markUnread(for: thread.id) + InboxReadStateStore.markUnread(for: thread.id, defaults: defaults) if unreadInboxThreads.contains(where: { $0.id == thread.id }) == false { unreadInboxThreads.append( InboxThreadSummary( @@ -786,7 +797,8 @@ final class HomeViewModel { containsPatch: thread.root.patch != nil || thread.subject.localizedCaseInsensitiveContains("[patch"), isUnread: InboxReadStateStore.isUnread( threadID: "\(mailingList.rid)#\(InboxThreadSummary.normalizationKey(for: thread.subject))", - lastActivityAt: thread.updated + lastActivityAt: thread.updated, + defaults: defaults ) ) return summary.isUnread ? summary : nil @@ -944,7 +956,8 @@ final class HomeViewModel { }.count : nil, updatedAt: .now - ) + ), + accountID: accountID ) } @@ -966,7 +979,7 @@ final class HomeViewModel { bannerSummary: snapshot.bannerSummary, updatedAt: .now ) - SystemStatusWidgetSnapshotStore.save(widgetSnapshot) + SystemStatusWidgetSnapshotStore.save(widgetSnapshot, accountID: accountID) } nonisolated static func buildItems(from jobs: [HomeJobPayload]) -> [HomeBuildItem] { |
