summaryrefslogtreecommitdiff
path: root/Hutch/App
diff options
context:
space:
mode:
Diffstat (limited to 'Hutch/App')
-rw-r--r--Hutch/App/AppState.swift15
-rw-r--r--Hutch/App/DeepLink.swift4
-rw-r--r--Hutch/App/RootView.swift7
3 files changed, 26 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()
diff --git a/Hutch/App/DeepLink.swift b/Hutch/App/DeepLink.swift
index a4b8269..e42bd6b 100644
--- a/Hutch/App/DeepLink.swift
+++ b/Hutch/App/DeepLink.swift
@@ -2,6 +2,7 @@ import Foundation
/// Represents a parsed `hutch://` deep link.
enum DeepLink: Equatable {
+ case home
/// hutch://git/<owner>/<repo>
case repository(owner: String, repo: String)
/// hutch://todo/<owner>/<tracker>/<ticketId>
@@ -19,6 +20,9 @@ enum DeepLink: Equatable {
let components = url.pathComponents(fromScheme: "hutch")
switch components.first {
+ case "home", nil:
+ self = .home
+
case "git" where components.count >= 3:
let owner = components[1]
let repo = components[2]
diff --git a/Hutch/App/RootView.swift b/Hutch/App/RootView.swift
index 9c4e71a..8d4eef1 100644
--- a/Hutch/App/RootView.swift
+++ b/Hutch/App/RootView.swift
@@ -161,6 +161,10 @@ struct RootView: View {
guard appState.isAuthenticated else { return }
switch link {
+ case .home:
+ homePath = NavigationPath()
+ appState.selectedTab = .home
+
case .repository(let owner, let repo):
resolveRepositoryLink(owner: owner, repo: repo)
@@ -284,12 +288,15 @@ private struct MoreNavigationRoot: View {
thread: thread,
onViewed: {
InboxReadStateStore.markViewed(max(Date(), thread.lastActivityAt), for: thread.id)
+ NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -1)
},
onMarkRead: {
InboxReadStateStore.markViewed(max(Date(), thread.lastActivityAt), for: thread.id)
+ NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -1)
},
onMarkUnread: {
InboxReadStateStore.markUnread(for: thread.id)
+ NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: 1)
}
)
}