Fix bugs in macOS app

This commit is contained in:
Thomas Ricouard 2023-01-16 21:15:33 +01:00
parent e9b7d48622
commit 9dc7fa00f9
7 changed files with 73 additions and 54 deletions

View file

@ -84,14 +84,12 @@ struct IceCubesApp: App {
private var sidebarView: some View { private var sidebarView: some View {
SideBarView(selectedTab: $selectedTab, SideBarView(selectedTab: $selectedTab,
popToRootTab: $popToRootTab, popToRootTab: $popToRootTab,
tabs: availableTabs) { selectedTab in tabs: availableTabs) {
ZStack { ZStack {
if let account = currentAccount.account, selectedTab == .profile {
AccountDetailView(account: account)
}
ForEach(availableTabs) { tab in ForEach(availableTabs) { tab in
if let account = currentAccount.account {
AccountDetailView(account: account)
.opacity(selectedTab == .profile ? 1 : 0)
.id(account.id)
}
if tab == selectedTab || sideBarLoadedTabs.contains(tab) { if tab == selectedTab || sideBarLoadedTabs.contains(tab) {
tab tab
.makeContentView(popToRootTab: $popToRootTab) .makeContentView(popToRootTab: $popToRootTab)

View file

@ -2,6 +2,7 @@ import SwiftUI
import Env import Env
import Account import Account
import DesignSystem import DesignSystem
import AppAccount
struct SideBarView<Content: View>: View { struct SideBarView<Content: View>: View {
@EnvironmentObject private var currentAccount: CurrentAccount @EnvironmentObject private var currentAccount: CurrentAccount
@ -10,18 +11,19 @@ struct SideBarView<Content: View>: View {
@Binding var selectedTab: Tab @Binding var selectedTab: Tab
@Binding var popToRootTab: Tab @Binding var popToRootTab: Tab
var tabs: [Tab] var tabs: [Tab]
@ViewBuilder var content: (Tab) -> Content @ViewBuilder var content: () -> Content
var body: some View { var body: some View {
HStack(spacing: 0) { HStack(spacing: 0) {
VStack(alignment: .center) { VStack(alignment: .center) {
if let account = currentAccount.account { if let account = currentAccount.account {
AvatarView(url: account.avatar) Button {
.frame(width: 70, height: 50) selectedTab = .profile
.background(selectedTab == .profile ? theme.secondaryBackgroundColor : .clear) } label: {
.onTapGesture { AvatarView(url: account.avatar, size: .status)
selectedTab = .profile }
} .frame(width: 70, height: 50)
.background(selectedTab == .profile ? theme.secondaryBackgroundColor : .clear)
} }
ForEach(tabs) { tab in ForEach(tabs) { tab in
Button { Button {
@ -48,7 +50,7 @@ struct SideBarView<Content: View>: View {
.background(.clear) .background(.clear)
Divider() Divider()
.edgesIgnoringSafeArea(.top) .edgesIgnoringSafeArea(.top)
content(selectedTab) content()
} }
.background(.thinMaterial) .background(.thinMaterial)
} }

View file

@ -22,8 +22,10 @@ struct ExploreTab: View {
.toolbar { .toolbar {
statusEditorToolbarItem(routeurPath: routeurPath, statusEditorToolbarItem(routeurPath: routeurPath,
visibility: preferences.serverPreferences?.postVisibility ?? .pub) visibility: preferences.serverPreferences?.postVisibility ?? .pub)
ToolbarItem(placement: .navigationBarLeading) { if !ProcessInfo.processInfo.isiOSAppOnMac {
AppAccountsSelectorView(routeurPath: routeurPath) ToolbarItem(placement: .navigationBarLeading) {
AppAccountsSelectorView(routeurPath: routeurPath)
}
} }
} }
} }

View file

@ -21,8 +21,10 @@ struct MessagesTab: View {
.withAppRouteur() .withAppRouteur()
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet) .withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
.toolbar { .toolbar {
ToolbarItem(placement: .navigationBarLeading) { if !ProcessInfo.processInfo.isiOSAppOnMac {
AppAccountsSelectorView(routeurPath: routeurPath) ToolbarItem(placement: .navigationBarLeading) {
AppAccountsSelectorView(routeurPath: routeurPath)
}
} }
} }
.id(currentAccount.account?.id) .id(currentAccount.account?.id)

View file

@ -21,8 +21,10 @@ struct NotificationsTab: View {
.toolbar { .toolbar {
statusEditorToolbarItem(routeurPath: routeurPath, statusEditorToolbarItem(routeurPath: routeurPath,
visibility: userPreferences.serverPreferences?.postVisibility ?? .pub) visibility: userPreferences.serverPreferences?.postVisibility ?? .pub)
ToolbarItem(placement: .navigationBarLeading) { if !ProcessInfo.processInfo.isiOSAppOnMac {
AppAccountsSelectorView(routeurPath: routeurPath) ToolbarItem(placement: .navigationBarLeading) {
AppAccountsSelectorView(routeurPath: routeurPath)
}
} }
} }
.id(currentAccount.account?.id) .id(currentAccount.account?.id)

View file

@ -138,8 +138,10 @@ struct TimelineTab: View {
} }
} }
if client.isAuth { if client.isAuth {
ToolbarItem(placement: .navigationBarLeading) { if !ProcessInfo.processInfo.isiOSAppOnMac {
AppAccountsSelectorView(routeurPath: routeurPath) ToolbarItem(placement: .navigationBarLeading) {
AppAccountsSelectorView(routeurPath: routeurPath)
}
} }
statusEditorToolbarItem(routeurPath: routeurPath, statusEditorToolbarItem(routeurPath: routeurPath,
visibility: preferences.serverPreferences?.postVisibility ?? .pub) visibility: preferences.serverPreferences?.postVisibility ?? .pub)

View file

@ -23,39 +23,9 @@ public struct AppAccountsSelectorView: View {
public var body: some View { public var body: some View {
Menu { Menu {
ForEach(accountsViewModel, id: \.appAccount.id) { viewModel in menuView
Section(viewModel.acct) {
Button {
if let account = currentAccount.account,
viewModel.account?.id == account.id {
routeurPath.navigate(to: .accountDetailWithAccount(account: account))
} else {
appAccounts.currentAccount = viewModel.appAccount
}
} label: {
HStack {
if viewModel.account?.id == currentAccount.account?.id {
Image(systemName: "checkmark.circle.fill")
}
Text("\(viewModel.account?.displayName ?? "")")
}
}
}
}
if accountCreationEnabled {
Divider()
Button {
routeurPath.presentedSheet = .addAccount
} label: {
Label("Add Account", systemImage: "person.badge.plus")
}
}
} label: { } label: {
if let avatar = currentAccount.account?.avatar { labelView
AvatarView(url: avatar, size: avatarSize)
} else {
EmptyView()
}
} }
.onAppear { .onAppear {
refreshAccounts() refreshAccounts()
@ -65,6 +35,46 @@ public struct AppAccountsSelectorView: View {
} }
} }
@ViewBuilder
private var labelView: some View {
if let avatar = currentAccount.account?.avatar {
AvatarView(url: avatar, size: avatarSize)
} else {
EmptyView()
}
}
@ViewBuilder
private var menuView: some View {
ForEach(accountsViewModel, id: \.appAccount.id) { viewModel in
Section(viewModel.acct) {
Button {
if let account = currentAccount.account,
viewModel.account?.id == account.id {
routeurPath.navigate(to: .accountDetailWithAccount(account: account))
} else {
appAccounts.currentAccount = viewModel.appAccount
}
} label: {
HStack {
if viewModel.account?.id == currentAccount.account?.id {
Image(systemName: "checkmark.circle.fill")
}
Text("\(viewModel.account?.displayName ?? "")")
}
}
}
}
if accountCreationEnabled {
Divider()
Button {
routeurPath.presentedSheet = .addAccount
} label: {
Label("Add Account", systemImage: "person.badge.plus")
}
}
}
private func refreshAccounts() { private func refreshAccounts() {
if accountsViewModel.isEmpty || appAccounts.availableAccounts.count != accountsViewModel.count { if accountsViewModel.isEmpty || appAccounts.availableAccounts.count != accountsViewModel.count {
accountsViewModel = [] accountsViewModel = []
@ -77,4 +87,5 @@ public struct AppAccountsSelectorView: View {
} }
} }
} }
} }