diff --git a/IceCubesApp/App/IceCubesApp.swift b/IceCubesApp/App/IceCubesApp.swift index 65ad4f81..d1109877 100644 --- a/IceCubesApp/App/IceCubesApp.swift +++ b/IceCubesApp/App/IceCubesApp.swift @@ -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) diff --git a/IceCubesApp/App/SideBarView.swift b/IceCubesApp/App/SideBarView.swift index 83498ecc..a923171e 100644 --- a/IceCubesApp/App/SideBarView.swift +++ b/IceCubesApp/App/SideBarView.swift @@ -2,6 +2,7 @@ import SwiftUI import Env import Account import DesignSystem +import AppAccount struct SideBarView: View { @EnvironmentObject private var currentAccount: CurrentAccount @@ -10,18 +11,19 @@ struct SideBarView: 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: View { .background(.clear) Divider() .edgesIgnoringSafeArea(.top) - content(selectedTab) + content() } .background(.thinMaterial) } diff --git a/IceCubesApp/App/Tabs/ExploreTab.swift b/IceCubesApp/App/Tabs/ExploreTab.swift index 2e114e6b..68a913e5 100644 --- a/IceCubesApp/App/Tabs/ExploreTab.swift +++ b/IceCubesApp/App/Tabs/ExploreTab.swift @@ -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) + } } } } diff --git a/IceCubesApp/App/Tabs/MessagesTab.swift b/IceCubesApp/App/Tabs/MessagesTab.swift index 3e00195f..1f965266 100644 --- a/IceCubesApp/App/Tabs/MessagesTab.swift +++ b/IceCubesApp/App/Tabs/MessagesTab.swift @@ -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) diff --git a/IceCubesApp/App/Tabs/NotificationTab.swift b/IceCubesApp/App/Tabs/NotificationTab.swift index 9d20ece7..b1ae19f0 100644 --- a/IceCubesApp/App/Tabs/NotificationTab.swift +++ b/IceCubesApp/App/Tabs/NotificationTab.swift @@ -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) diff --git a/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift b/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift index ff337cc4..7d14d31a 100644 --- a/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift +++ b/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift @@ -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) diff --git a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift index 2fcd14ec..3ffdcc98 100644 --- a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift +++ b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift @@ -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 { } } } + }