diff --git a/IceCubesApp/App/AppAccounts/AppAccountView.swift b/IceCubesApp/App/AppAccounts/AppAccountView.swift index 047b5ae5..13249ba7 100644 --- a/IceCubesApp/App/AppAccounts/AppAccountView.swift +++ b/IceCubesApp/App/AppAccounts/AppAccountView.swift @@ -1,7 +1,9 @@ import SwiftUI import DesignSystem +import Env struct AppAccountView: View { + @EnvironmentObject private var routeurPath: RouterPath @EnvironmentObject var appAccounts: AppAccountsManager @StateObject var viewModel: AppAccountViewModel @@ -25,11 +27,22 @@ struct AppAccountView: View { .foregroundColor(.gray) } } + Spacer() + Image(systemName: "chevron.right") + .foregroundColor(.gray) } .onAppear { Task { await viewModel.fetchAccount() } } + .onTapGesture { + if appAccounts.currentAccount.id == viewModel.appAccount.id, + let account = viewModel.account { + routeurPath.navigate(to: .accountDetailWithAccount(account: account)) + } else { + appAccounts.currentAccount = viewModel.appAccount + } + } } } diff --git a/IceCubesApp/App/AppAccounts/AppAccountViewModel.swift b/IceCubesApp/App/AppAccounts/AppAccountViewModel.swift index f20418e0..47f77510 100644 --- a/IceCubesApp/App/AppAccounts/AppAccountViewModel.swift +++ b/IceCubesApp/App/AppAccounts/AppAccountViewModel.swift @@ -9,6 +9,10 @@ public class AppAccountViewModel: ObservableObject { @Published var account: Account? + var acct: String { + "@\(account?.acct ?? "...")@\(appAccount.server)" + } + init(appAccount: AppAccount) { self.appAccount = appAccount self.client = .init(server: appAccount.server, oauthToken: appAccount.oauthToken) diff --git a/IceCubesApp/App/AppAccounts/AppAccountsSelectorView.swift b/IceCubesApp/App/AppAccounts/AppAccountsSelectorView.swift index 5ff4f933..3b54a84b 100644 --- a/IceCubesApp/App/AppAccounts/AppAccountsSelectorView.swift +++ b/IceCubesApp/App/AppAccounts/AppAccountsSelectorView.swift @@ -11,9 +11,31 @@ struct AppAccountsSelectorView: View { @State private var accountsViewModel: [AppAccountViewModel] = [] var body: some View { - Button { - if let account = currentAccount.account { - routeurPath.navigate(to: .accountDetailWithAccount(account: account)) + 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 ?? "")") + } + } + } + } + Divider() + Button { + routeurPath.presentedSheet = .addAccount + } label: { + Label("Add Account", systemImage: "person.badge.plus") } } label: { if let avatar = currentAccount.account?.avatar { @@ -25,25 +47,6 @@ struct AppAccountsSelectorView: View { .onAppear { refreshAccounts() } - .contextMenu { - ForEach(accountsViewModel, id: \.appAccount.id) { viewModel in - Button { - appAccounts.currentAccount = viewModel.appAccount - } label: { - HStack { - if viewModel.account?.id == currentAccount.account?.id { - Image(systemName: "checkmark.circle.fill") - } - Text("\(viewModel.account?.displayName ?? "")") - } - } - } - Button { - routeurPath.presentedSheet = .addAccount - } label: { - Label("Add Account", systemImage: "person.badge.plus") - } - } .onChange(of: currentAccount.account?.id) { _ in refreshAccounts() } @@ -54,9 +57,9 @@ struct AppAccountsSelectorView: View { accountsViewModel = [] for account in appAccounts.availableAccounts { let viewModel: AppAccountViewModel = .init(appAccount: account) - accountsViewModel.append(viewModel) Task { await viewModel.fetchAccount() + accountsViewModel.append(viewModel) } } } diff --git a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift index a62e44e4..ca372f61 100644 --- a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift +++ b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift @@ -18,6 +18,8 @@ struct SettingsTabs: View { @State private var addAccountSheetPresented = false + @Binding var popToRootTab: Tab + var body: some View { NavigationStack(path: $routeurPath.path) { Form { @@ -43,19 +45,17 @@ struct SettingsTabs: View { } .withSafariRouteur() .environmentObject(routeurPath) + .onChange(of: $popToRootTab.wrappedValue) { popToRootTab in + if popToRootTab == .notifications { + routeurPath.path = [] + } + } } private var accountsSection: some View { Section("Accounts") { ForEach(appAccountsManager.availableAccounts) { account in - HStack { - AppAccountView(viewModel: .init(appAccount: account)) - } - .onTapGesture { - withAnimation { - appAccountsManager.currentAccount = account - } - } + AppAccountView(viewModel: .init(appAccount: account)) } .onDelete { indexSet in if let index = indexSet.first { diff --git a/IceCubesApp/App/Tabs/Tabs.swift b/IceCubesApp/App/Tabs/Tabs.swift index 1184e55a..4808e868 100644 --- a/IceCubesApp/App/Tabs/Tabs.swift +++ b/IceCubesApp/App/Tabs/Tabs.swift @@ -31,7 +31,7 @@ enum Tab: Int, Identifiable, Hashable { case .messages: MessagesTab(popToRootTab: popToRootTab) case .settings: - SettingsTabs() + SettingsTabs(popToRootTab: popToRootTab) case .other: EmptyView() } diff --git a/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift b/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift index 8bd0d6cd..d4c95abf 100644 --- a/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift +++ b/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift @@ -33,7 +33,6 @@ struct ConversationsListRow: View { .font(.footnote) } Text(conversation.lastStatus.content.asRawText) - .foregroundColor(.gray) .multilineTextAlignment(.leading) } Spacer()