Routeur: Handle same instance status url

This commit is contained in:
Thomas Ricouard 2022-12-27 08:31:47 +01:00
parent e5fb3acd07
commit 9209258f4c
5 changed files with 20 additions and 0 deletions

View file

@ -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
}
}
}

View file

@ -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
}
}
}

View file

@ -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)

View file

@ -31,6 +31,7 @@ struct TimelineTab: View {
}
}
.onAppear {
routeurPath.client = client
if !client.isAuth {
timeline = .pub
}

View file

@ -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
}