2023-01-17 13:02:05 +01:00
|
|
|
import Account
|
|
|
|
import AppAccount
|
|
|
|
import Conversations
|
2023-01-22 06:53:18 +01:00
|
|
|
import DesignSystem
|
2023-01-17 13:02:05 +01:00
|
|
|
import Env
|
|
|
|
import Models
|
|
|
|
import Network
|
|
|
|
import SwiftUI
|
|
|
|
|
2023-09-18 21:03:52 +02:00
|
|
|
@MainActor
|
2023-01-17 13:02:05 +01:00
|
|
|
struct ProfileTab: View {
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(AppAccountsManager.self) private var appAccount
|
2023-09-18 21:03:52 +02:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(Client.self) private var client
|
|
|
|
@Environment(CurrentAccount.self) private var currentAccount
|
|
|
|
@State private var routerPath = RouterPath()
|
2023-10-05 08:22:45 +02:00
|
|
|
@State private var scrollToTopSignal: Int = 0
|
2023-01-17 13:02:05 +01:00
|
|
|
@Binding var popToRootTab: Tab
|
|
|
|
|
|
|
|
var body: some View {
|
2023-01-17 15:14:50 +01:00
|
|
|
NavigationStack(path: $routerPath.path) {
|
2023-01-17 13:02:05 +01:00
|
|
|
if let account = currentAccount.account {
|
2023-10-05 08:22:45 +02:00
|
|
|
AccountDetailView(account: account, scrollToTopSignal: $scrollToTopSignal)
|
2023-01-17 15:14:50 +01:00
|
|
|
.withAppRouter()
|
|
|
|
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)
|
2023-01-22 06:53:18 +01:00
|
|
|
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
|
2023-01-30 22:24:30 +01:00
|
|
|
.id(account.id)
|
2023-01-17 13:02:05 +01:00
|
|
|
} else {
|
2023-10-05 08:22:45 +02:00
|
|
|
AccountDetailView(account: .placeholder(), scrollToTopSignal: $scrollToTopSignal)
|
2023-01-17 13:02:05 +01:00
|
|
|
.redacted(reason: .placeholder)
|
2023-09-18 18:55:11 +02:00
|
|
|
.allowsHitTesting(false)
|
2023-01-17 13:02:05 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 07:01:23 +02:00
|
|
|
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
|
|
|
|
if newValue == .profile {
|
2023-10-05 08:22:45 +02:00
|
|
|
if routerPath.path.isEmpty {
|
|
|
|
scrollToTopSignal += 1
|
|
|
|
} else {
|
|
|
|
routerPath.path = []
|
|
|
|
}
|
2023-01-17 13:02: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-17 13:02:05 +01:00
|
|
|
}
|
|
|
|
.onAppear {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.client = client
|
2023-01-17 13:02:05 +01:00
|
|
|
}
|
2023-01-17 15:14:50 +01:00
|
|
|
.withSafariRouter()
|
2023-09-18 07:01:23 +02:00
|
|
|
.environment(routerPath)
|
2023-01-17 13:02:05 +01:00
|
|
|
}
|
|
|
|
}
|