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 {
SideBarView(selectedTab: $selectedTab,
popToRootTab: $popToRootTab,
tabs: availableTabs) { selectedTab in
tabs: availableTabs) {
ZStack {
if let account = currentAccount.account, selectedTab == .profile {
AccountDetailView(account: account)
}
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) {
tab
.makeContentView(popToRootTab: $popToRootTab)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -23,39 +23,9 @@ public struct AppAccountsSelectorView: View {
public var body: some View {
Menu {
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")
}
}
menuView
} label: {
if let avatar = currentAccount.account?.avatar {
AvatarView(url: avatar, size: avatarSize)
} else {
EmptyView()
}
labelView
}
.onAppear {
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() {
if accountsViewModel.isEmpty || appAccounts.availableAccounts.count != accountsViewModel.count {
accountsViewModel = []
@ -77,4 +87,5 @@ public struct AppAccountsSelectorView: View {
}
}
}
}