From 9209258f4c11a7b57abccef5919cc8b735f103cf Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Tue, 27 Dec 2022 08:31:47 +0100 Subject: [PATCH] Routeur: Handle same instance status url --- IceCubesApp/App/Tabs/AccountTab.swift | 4 ++++ IceCubesApp/App/Tabs/ExploreTab.swift | 6 ++++++ IceCubesApp/App/Tabs/NotificationTab.swift | 2 ++ IceCubesApp/App/Tabs/TimelineTab.swift | 1 + Packages/Env/Sources/Env/Routeur.swift | 7 +++++++ 5 files changed, 20 insertions(+) diff --git a/IceCubesApp/App/Tabs/AccountTab.swift b/IceCubesApp/App/Tabs/AccountTab.swift index 018e23c6..4296e3f7 100644 --- a/IceCubesApp/App/Tabs/AccountTab.swift +++ b/IceCubesApp/App/Tabs/AccountTab.swift @@ -6,6 +6,7 @@ import Models import Shimmer struct AccountTab: View { + @EnvironmentObject private var client: Client @EnvironmentObject private var currentAccount: CurrentAccount @StateObject private var routeurPath = RouterPath() @Binding var popToRootTab: IceCubesApp.Tab @@ -28,5 +29,8 @@ struct AccountTab: View { routeurPath.path = [] } } + .onAppear { + routeurPath.client = client + } } } diff --git a/IceCubesApp/App/Tabs/ExploreTab.swift b/IceCubesApp/App/Tabs/ExploreTab.swift index 8fd7e56b..09fb4207 100644 --- a/IceCubesApp/App/Tabs/ExploreTab.swift +++ b/IceCubesApp/App/Tabs/ExploreTab.swift @@ -3,8 +3,11 @@ import Env import Models import Shimmer import Explore +import Env +import Network struct ExploreTab: View { + @EnvironmentObject private var client: Client @StateObject private var routeurPath = RouterPath() @Binding var popToRootTab: IceCubesApp.Tab @@ -20,5 +23,8 @@ struct ExploreTab: View { routeurPath.path = [] } } + .onAppear { + routeurPath.client = client + } } } diff --git a/IceCubesApp/App/Tabs/NotificationTab.swift b/IceCubesApp/App/Tabs/NotificationTab.swift index 85a374ce..e6719914 100644 --- a/IceCubesApp/App/Tabs/NotificationTab.swift +++ b/IceCubesApp/App/Tabs/NotificationTab.swift @@ -5,6 +5,7 @@ import Network import Notifications struct NotificationsTab: View { + @EnvironmentObject private var client: Client @EnvironmentObject private var watcher: StreamWatcher @StateObject private var routeurPath = RouterPath() @Binding var popToRootTab: IceCubesApp.Tab @@ -16,6 +17,7 @@ struct NotificationsTab: View { .withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet) } .onAppear { + routeurPath.client = client watcher.unreadNotificationsCount = 0 } .environmentObject(routeurPath) diff --git a/IceCubesApp/App/Tabs/TimelineTab.swift b/IceCubesApp/App/Tabs/TimelineTab.swift index 7e02f065..5d6821c0 100644 --- a/IceCubesApp/App/Tabs/TimelineTab.swift +++ b/IceCubesApp/App/Tabs/TimelineTab.swift @@ -31,6 +31,7 @@ struct TimelineTab: View { } } .onAppear { + routeurPath.client = client if !client.isAuth { timeline = .pub } diff --git a/Packages/Env/Sources/Env/Routeur.swift b/Packages/Env/Sources/Env/Routeur.swift index e5e292f9..428b8089 100644 --- a/Packages/Env/Sources/Env/Routeur.swift +++ b/Packages/Env/Sources/Env/Routeur.swift @@ -1,6 +1,7 @@ import Foundation import SwiftUI import Models +import Network public enum RouteurDestinations: Hashable { case accountDetail(id: String) @@ -28,6 +29,8 @@ public enum SheetDestinations: Identifiable { } public class RouterPath: ObservableObject { + public var client: Client? + @Published public var path: [RouteurDestinations] = [] @Published public var presentedSheet: SheetDestinations? @@ -45,6 +48,10 @@ public class RouterPath: ObservableObject { } else if let mention = status.mentions.first(where: { $0.url == url }) { navigate(to: .accountDetail(id: mention.id)) return .handled + } else if let client = client, + let id = status.content.findStatusesIds(instance: client.server)?.first(where: { String($0) == url.lastPathComponent}) { + navigate(to: .statusDetail(id: String(id))) + return .handled } return .systemAction }