IceCubes/IceCubesApp/App/Tabs/ProfileTab.swift

54 lines
1.5 KiB
Swift
Raw Normal View History

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