Enable account switcher on macOS

This commit is contained in:
Thomas Ricouard 2023-01-16 21:27:54 +01:00
parent 9dc7fa00f9
commit 451cc7a4ac
2 changed files with 24 additions and 13 deletions

View File

@ -16,15 +16,15 @@ struct SideBarView<Content: View>: View {
var body: some View {
HStack(spacing: 0) {
VStack(alignment: .center) {
if let account = currentAccount.account {
Button {
selectedTab = .profile
} label: {
AvatarView(url: account.avatar, size: .status)
}
.frame(width: 70, height: 50)
.background(selectedTab == .profile ? theme.secondaryBackgroundColor : .clear)
Button {
selectedTab = .profile
} label: {
AppAccountsSelectorView(routeurPath: RouterPath(),
accountCreationEnabled: false,
avatarSize: .status)
}
.frame(width: 70, height: 60)
.background(selectedTab == .profile ? theme.secondaryBackgroundColor : .clear)
ForEach(tabs) { tab in
Button {
if tab == selectedTab {

View File

@ -22,10 +22,19 @@ public struct AppAccountsSelectorView: View {
}
public var body: some View {
Menu {
menuView
} label: {
labelView
Group {
if ProcessInfo.processInfo.isiOSAppOnMac {
labelView
.contextMenu {
menuView
}
} else {
Menu {
menuView
} label: {
labelView
}
}
}
.onAppear {
refreshAccounts()
@ -82,7 +91,9 @@ public struct AppAccountsSelectorView: View {
let viewModel: AppAccountViewModel = .init(appAccount: account)
Task {
await viewModel.fetchAccount()
accountsViewModel.append(viewModel)
if !accountsViewModel.contains(where: { $0.acct == viewModel.acct }) {
accountsViewModel.append(viewModel)
}
}
}
}