Add access to profile from account selector

This commit is contained in:
Thomas Ricouard 2024-01-05 18:57:02 +01:00
parent 8152db745d
commit bfc1f61e4b
5 changed files with 21 additions and 11 deletions

View File

@ -88,7 +88,8 @@ struct SideBarView<Content: View>: View {
}
} label: {
ZStack(alignment: .topTrailing) {
AppAccountView(viewModel: .init(appAccount: account, isCompact: true))
AppAccountView(viewModel: .init(appAccount: account, isCompact: true),
isParentPresented: .constant(false))
if showBadge,
let token = account.oauthToken,
let notificationsCount = userPreferences.notificationsCount[token],

View File

@ -101,7 +101,7 @@ struct SettingsTabs: View {
.tint(.red)
}
}
AppAccountView(viewModel: .init(appAccount: account))
AppAccountView(viewModel: .init(appAccount: account), isParentPresented: .constant(false))
}
}
.onDelete { indexSet in

View File

@ -12,8 +12,11 @@ public struct AppAccountView: View {
@State var viewModel: AppAccountViewModel
public init(viewModel: AppAccountViewModel) {
@Binding var isParentPresented: Bool
public init(viewModel: AppAccountViewModel, isParentPresented: Binding<Bool>) {
self.viewModel = viewModel
_isParentPresented = isParentPresented
}
public var body: some View {
@ -47,8 +50,14 @@ public struct AppAccountView: View {
if appAccounts.currentAccount.id == viewModel.appAccount.id,
let account = viewModel.account
{
routerPath.navigate(to: .accountSettingsWithAccount(account: account, appAccount: viewModel.appAccount))
HapticManager.shared.fireHaptic(.buttonPress)
if viewModel.isInSettings {
routerPath.navigate(to: .accountSettingsWithAccount(account: account, appAccount: viewModel.appAccount))
HapticManager.shared.fireHaptic(.buttonPress)
} else {
isParentPresented = false
routerPath.navigate(to: .accountDetailWithAccount(account: account))
HapticManager.shared.fireHaptic(.buttonPress)
}
} else {
var transation = Transaction()
transation.disablesAnimations = true
@ -100,7 +109,7 @@ public struct AppAccountView: View {
.foregroundStyle(Color.secondary)
}
}
if viewModel.isInNavigation {
if viewModel.isInSettings {
Spacer()
Image(systemName: "chevron.right")
.foregroundStyle(.secondary)

View File

@ -13,7 +13,7 @@ import SwiftUI
var appAccount: AppAccount
let client: Client
let isCompact: Bool
let isInNavigation: Bool
let isInSettings: Bool
let showBadge: Bool
var account: Account? {
@ -32,10 +32,10 @@ import SwiftUI
}
}
public init(appAccount: AppAccount, isCompact: Bool = false, isInNavigation: Bool = true, showBadge: Bool = false) {
public init(appAccount: AppAccount, isCompact: Bool = false, isInSettings: Bool = true, showBadge: Bool = false) {
self.appAccount = appAccount
self.isCompact = isCompact
self.isInNavigation = isInNavigation
self.isInSettings = isInSettings
self.showBadge = showBadge
client = .init(server: appAccount.server, oauthToken: appAccount.oauthToken)
}

View File

@ -93,7 +93,7 @@ public struct AppAccountsSelectorView: View {
List {
Section {
ForEach(accountsViewModel.sorted { $0.acct < $1.acct }, id: \.appAccount.id) { viewModel in
AppAccountView(viewModel: viewModel)
AppAccountView(viewModel: viewModel, isParentPresented: $isPresented)
}
addAccountButton
}
@ -181,7 +181,7 @@ public struct AppAccountsSelectorView: View {
private func refreshAccounts() {
accountsViewModel = []
for account in appAccounts.availableAccounts {
let viewModel: AppAccountViewModel = .init(appAccount: account, isInNavigation: false, showBadge: true)
let viewModel: AppAccountViewModel = .init(appAccount: account, isInSettings: false, showBadge: true)
accountsViewModel.append(viewModel)
}
}