2023-01-17 11:36:01 +01:00
|
|
|
import AppAccount
|
2023-01-22 06:53:18 +01:00
|
|
|
import DesignSystem
|
2022-12-23 10:41:55 +01:00
|
|
|
import Env
|
|
|
|
import Explore
|
2023-01-17 11:36:01 +01:00
|
|
|
import Models
|
2022-12-27 08:31:47 +01:00
|
|
|
import Network
|
2023-01-17 11:36:01 +01:00
|
|
|
import SwiftUI
|
2022-12-23 10:41:55 +01:00
|
|
|
|
2023-09-19 09:18:20 +02:00
|
|
|
@MainActor
|
2022-12-23 10:41:55 +01:00
|
|
|
struct ExploreTab: View {
|
2023-09-18 21:03:52 +02:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-09-19 09:18:20 +02:00
|
|
|
@Environment(UserPreferences.self) private var preferences
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(CurrentAccount.self) private var currentAccount
|
|
|
|
@Environment(Client.self) private var client
|
|
|
|
@State private var routerPath = RouterPath()
|
2023-10-05 08:22:45 +02:00
|
|
|
@State private var scrollToTopSignal: Int = 0
|
2022-12-27 09:25:26 +01:00
|
|
|
@Binding var popToRootTab: Tab
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-12-23 10:41:55 +01:00
|
|
|
var body: some View {
|
2023-01-17 15:14:50 +01:00
|
|
|
NavigationStack(path: $routerPath.path) {
|
2023-10-05 08:22:45 +02:00
|
|
|
ExploreView(scrollToTopSignal: $scrollToTopSignal)
|
2023-01-17 15:14:50 +01:00
|
|
|
.withAppRouter()
|
|
|
|
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)
|
2024-01-23 08:51:58 +01:00
|
|
|
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.30), for: .navigationBar)
|
2022-12-29 17:22:07 +01:00
|
|
|
.toolbar {
|
2023-12-29 18:50:53 +01:00
|
|
|
ToolbarTab(routerPath: $routerPath)
|
2022-12-29 17:22:07 +01:00
|
|
|
}
|
2022-12-23 10:41:55 +01:00
|
|
|
}
|
2023-01-17 15:14:50 +01:00
|
|
|
.withSafariRouter()
|
2023-09-18 07:01:23 +02:00
|
|
|
.environment(routerPath)
|
|
|
|
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
|
|
|
|
if newValue == .explore {
|
2023-10-05 08:22:45 +02:00
|
|
|
if routerPath.path.isEmpty {
|
|
|
|
scrollToTopSignal += 1
|
|
|
|
} else {
|
|
|
|
routerPath.path = []
|
|
|
|
}
|
2022-12-24 11:50:05 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 07:01:23 +02:00
|
|
|
.onChange(of: client.id) {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.path = []
|
2023-01-02 19:23:44 +01:00
|
|
|
}
|
2022-12-27 08:31:47 +01:00
|
|
|
.onAppear {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.client = client
|
2022-12-27 08:31:47 +01:00
|
|
|
}
|
2022-12-23 10:41:55 +01:00
|
|
|
}
|
|
|
|
}
|