diff options
Diffstat (limited to 'Hutch/App/AppState.swift')
| -rw-r--r-- | Hutch/App/AppState.swift | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Hutch/App/AppState.swift b/Hutch/App/AppState.swift index e74a58b..9788c85 100644 --- a/Hutch/App/AppState.swift +++ b/Hutch/App/AppState.swift @@ -77,11 +77,13 @@ final class AppState { let user = try await fetchMe() currentUser = user authPhase = .authenticated + await refreshNeedsAttentionSnapshot() } catch { try? KeychainHelper.deleteToken() client.setToken(nil) currentUser = nil authPhase = .unauthenticated + NeedsAttentionSnapshotStore.clear() } } @@ -98,6 +100,7 @@ final class AppState { try KeychainHelper.saveToken(token) currentUser = user authPhase = .authenticated + await refreshNeedsAttentionSnapshot() } catch { // Roll back — don't leave an invalid token in the client. client.setToken(nil) @@ -111,6 +114,7 @@ final class AppState { HTTPCookieStorage.shared.cookies?.forEach { HTTPCookieStorage.shared.deleteCookie($0) } await clearWebData() clearWebContentRenderCaches() + NeedsAttentionSnapshotStore.clear() authPhase = .unauthenticated selectedTab = .home } @@ -125,6 +129,7 @@ final class AppState { HTTPCookieStorage.shared.cookies?.forEach { HTTPCookieStorage.shared.deleteCookie($0) } await clearWebData() clearWebContentRenderCaches() + NeedsAttentionSnapshotStore.clear() authPhase = .unauthenticated selectedTab = .home @@ -270,6 +275,16 @@ final class AppState { selectedTab = .home } + private func refreshNeedsAttentionSnapshot() async { + guard let currentUser else { + NeedsAttentionSnapshotStore.clear() + return + } + + let viewModel = HomeViewModel(currentUser: currentUser, client: client) + await viewModel.loadDashboard() + } + private func clearWebData() async { await withCheckedContinuation { continuation in let dataTypes = WKWebsiteDataStore.allWebsiteDataTypes() |
