summaryrefslogtreecommitdiff
path: root/DomainDig/RootTabView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'DomainDig/RootTabView.swift')
-rw-r--r--DomainDig/RootTabView.swift32
1 files changed, 32 insertions, 0 deletions
diff --git a/DomainDig/RootTabView.swift b/DomainDig/RootTabView.swift
index f2c9f6c..72038a1 100644
--- a/DomainDig/RootTabView.swift
+++ b/DomainDig/RootTabView.swift
@@ -11,6 +11,7 @@ private enum RootTab: Hashable {
struct RootTabView: View {
@Bindable var viewModel: DomainViewModel
@State private var purchaseService = PurchaseService.shared
+ @State private var intentRouter = DomainDigIntentRouter.shared
@State private var selectedTab: RootTab = FeatureAccessService.currentTier == .free ? .inspect : .dashboard
var body: some View {
@@ -82,5 +83,36 @@ struct RootTabView: View {
selectedTab = .dashboard
}
}
+ .onOpenURL { url in
+ guard let action = DomainDigDeepLink.action(from: url) else { return }
+ perform(action)
+ }
+ .onChange(of: intentRouter.pendingAction) { _, action in
+ consume(action)
+ }
+ .task {
+ consume(intentRouter.pendingAction)
+ }
+ }
+
+ private func consume(_ action: DomainDigDeepLink.Action?) {
+ guard let action else { return }
+ intentRouter.pendingAction = nil
+ perform(action)
+ }
+
+ private func perform(_ action: DomainDigDeepLink.Action) {
+ switch action {
+ case let .inspect(domain):
+ viewModel.domain = domain
+ selectedTab = .inspect
+ viewModel.run()
+ case let .watch(domain):
+ // On success show the dashboard (where tracked domains live); on
+ // failure stay put so the upgrade/paywall alert surfaces in place.
+ if viewModel.trackDomain(domain: domain, availabilityStatus: nil) {
+ selectedTab = .dashboard
+ }
+ }
}
}