Commit bc2dcb7e82
bc2dcb7e825f5d814a6f456eca7b47e2f08b9110
parent: 948330fe88
Unsigned
cmc <hello@cleberg.net> · 2026-03-23 01:40 UTC
feat: surface an alert when a deep link fails to resolve
Layout: unified · split
Hutch/App/AppState.swift
+10
| @@ -54,6 +54,7 @@ final class AppState { |
| 54 | 54 | /// Set by the deep link handler; consumed by RootView to drive navigation. |
| 55 | 55 | var pendingDeepLink: DeepLink? |
| 56 | 56 | var pendingTabNavigation: TabNavigationTarget? |
| 57 | var deepLinkError: String? |
| 57 | 58 | |
| 58 | 59 | // MARK: - Init |
| 59 | 60 | |
| @@ -182,6 +183,14 @@ final class AppState { |
| 182 | 183 | selectedTab = .more |
| 183 | 184 | } |
| 184 | 185 | |
| 186 | func presentRepositoryDeepLinkError() { |
| 187 | deepLinkError = "The repository could not be found or is inaccessible." |
| 188 | } |
| 189 | |
| 190 | func presentTicketDeepLinkError() { |
| 191 | deepLinkError = "The ticket could not be found or is inaccessible." |
| 192 | } |
| 193 | |
| 185 | 194 | // MARK: - Private |
| 186 | 195 | |
| 187 | 196 | private static let meQuery = """ |
| @@ -257,6 +266,7 @@ final class AppState { |
| 257 | 266 | currentUser = nil |
| 258 | 267 | pendingDeepLink = nil |
| 259 | 268 | pendingTabNavigation = nil |
| 269 | deepLinkError = nil |
| 260 | 270 | selectedTab = .home |
| 261 | 271 | } |
| 262 | 272 | |
Hutch/App/RootView.swift
+21 −2
| @@ -12,6 +12,8 @@ struct RootView: View { |
| 12 | 12 | @State private var isResolvingDeepLink = false |
| 13 | 13 | |
| 14 | 14 | var body: some View { |
| 15 | @Bindable var appState = appState |
| 16 | |
| 15 | 17 | Group { |
| 16 | 18 | switch appState.authPhase { |
| 17 | 19 | case .launching: |
| @@ -37,6 +39,23 @@ struct RootView: View { |
| 37 | 39 | .onChange(of: appState.pendingTabNavigation) { _, newValue in |
| 38 | 40 | consumePendingTabNavigationIfPossible(newValue) |
| 39 | 41 | } |
| 42 | .alert( |
| 43 | "Couldn't Open Link", |
| 44 | isPresented: Binding( |
| 45 | get: { appState.deepLinkError != nil }, |
| 46 | set: { isPresented in |
| 47 | if !isPresented { |
| 48 | appState.deepLinkError = nil |
| 49 | } |
| 50 | } |
| 51 | ) |
| 52 | ) { |
| 53 | Button("OK") { |
| 54 | appState.deepLinkError = nil |
| 55 | } |
| 56 | } message: { |
| 57 | Text(appState.deepLinkError ?? "") |
| 58 | } |
| 40 | 59 | } |
| 41 | 60 | |
| 42 | 61 | // MARK: - Tab View |
| @@ -198,7 +217,7 @@ struct RootView: View { |
| 198 | 217 | await settleNavigationTransition() |
| 199 | 218 | repoPath.append(summary) |
| 200 | 219 | } catch { |
| 201 | | // Silently fail — the repo may not exist or be inaccessible |
| 220 | appState.presentRepositoryDeepLinkError() |
| 202 | 221 | } |
| 203 | 222 | } |
| 204 | 223 | } |
| @@ -221,7 +240,7 @@ struct RootView: View { |
| 221 | 240 | ticketId: ticketId |
| 222 | 241 | )) |
| 223 | 242 | } catch { |
| 224 | | // Silently fail |
| 243 | appState.presentTicketDeepLinkError() |
| 225 | 244 | } |
| 226 | 245 | } |
| 227 | 246 | } |
HutchTests/AppStateTests.swift
added
+25
| @@ -0,0 +1,25 @@ |
| 1 | import Testing |
| 2 | @testable import Hutch |
| 3 | |
| 4 | struct AppStateTests { |
| 5 | |
| 6 | @Test |
| 7 | @MainActor |
| 8 | func presentRepositoryDeepLinkErrorSetsUserFacingMessage() { |
| 9 | let appState = AppState() |
| 10 | |
| 11 | appState.presentRepositoryDeepLinkError() |
| 12 | |
| 13 | #expect(appState.deepLinkError == "The repository could not be found or is inaccessible.") |
| 14 | } |
| 15 | |
| 16 | @Test |
| 17 | @MainActor |
| 18 | func presentTicketDeepLinkErrorSetsUserFacingMessage() { |
| 19 | let appState = AppState() |
| 20 | |
| 21 | appState.presentTicketDeepLinkError() |
| 22 | |
| 23 | #expect(appState.deepLinkError == "The ticket could not be found or is inaccessible.") |
| 24 | } |
| 25 | } |