diff --git a/Mlem/Views/Tabs/Settings/Components/AccountButtonView.swift b/Mlem/Views/Tabs/Settings/Components/AccountButtonView.swift index 332498791..13443ff85 100644 --- a/Mlem/Views/Tabs/Settings/Components/AccountButtonView.swift +++ b/Mlem/Views/Tabs/Settings/Components/AccountButtonView.swift @@ -15,6 +15,7 @@ struct AccountButtonView: View { @Environment(\.setAppFlow) private var setFlow @State var showingSignOutConfirmation: Bool = false + @Binding var isSwitching: Bool enum CaptionState { case instanceOnly, timeOnly, instanceAndTime @@ -23,9 +24,10 @@ struct AccountButtonView: View { let account: SavedAccount let caption: CaptionState - init(account: SavedAccount, caption: CaptionState = .instanceAndTime) { + init(account: SavedAccount, caption: CaptionState = .instanceAndTime, isSwitching: Binding) { self.account = account self.caption = caption + self._isSwitching = isSwitching } var timeText: String? { @@ -126,6 +128,7 @@ struct AccountButtonView: View { private func setFlow(using account: SavedAccount?) { if let account { + isSwitching = true setFlow(.account(account)) return } diff --git a/Mlem/Views/Tabs/Settings/Components/AccountListView.swift b/Mlem/Views/Tabs/Settings/Components/AccountListView.swift index a137283f4..d4c73ec33 100644 --- a/Mlem/Views/Tabs/Settings/Components/AccountListView.swift +++ b/Mlem/Views/Tabs/Settings/Components/AccountListView.swift @@ -31,6 +31,8 @@ struct AccountListView: View { @State private var isShowingInstanceAdditionSheet: Bool = false + @State var isSwitching: Bool = false + struct AccountGroup { let header: String let accounts: [SavedAccount] @@ -47,38 +49,41 @@ struct AccountListView: View { var body: some View { Group { - if accountsTracker.savedAccounts.count > 3 && groupAccountSort { - ForEach(Array(accountGroups.enumerated()), id: \.offset) { offset, group in - Section { - ForEach(group.accounts, id: \.self) { account in - AccountButtonView( - account: account, - caption: accountSort != .instance || group.header == "Other" ? .instanceAndTime : .timeOnly - ) + if !isSwitching { + if accountsTracker.savedAccounts.count > 3 && groupAccountSort { + ForEach(Array(accountGroups.enumerated()), id: \.offset) { offset, group in + Section { + ForEach(group.accounts, id: \.self) { account in + AccountButtonView( + account: account, + caption: accountSort != .instance || group.header == "Other" ? .instanceAndTime : .timeOnly, + isSwitching: $isSwitching + ) + } + } header: { + if offset == 0 { + topHeader(text: group.header) + } else { + Text(group.header) + } } - } header: { - if offset == 0 { - topHeader(text: group.header) - } else { - Text(group.header) + } + } else { + Section(header: topHeader()) { + ForEach(accounts, id: \.self) { account in + AccountButtonView(account: account, isSwitching: $isSwitching) } } } - } else { - Section(header: topHeader()) { - ForEach(accounts, id: \.self) { account in - AccountButtonView(account: account) + Section { + Button { + isShowingInstanceAdditionSheet = true + } label: { + Label("Add Account", systemImage: "plus") } + .accessibilityLabel("Add a new account.") } } - Section { - Button { - isShowingInstanceAdditionSheet = true - } label: { - Label("Add Account", systemImage: "plus") - } - .accessibilityLabel("Add a new account.") - } } .sheet(isPresented: $isShowingInstanceAdditionSheet) { AddSavedInstanceView(onboarding: false)