Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Dec 30, 2023
1 parent 33cac7a commit 04cd2e0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
5 changes: 4 additions & 1 deletion Mlem/Views/Tabs/Settings/Components/AccountButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Bool>) {
self.account = account
self.caption = caption
self._isSwitching = isSwitching
}

var timeText: String? {
Expand Down Expand Up @@ -126,6 +128,7 @@ struct AccountButtonView: View {

private func setFlow(using account: SavedAccount?) {
if let account {
isSwitching = true
setFlow(.account(account))
return
}
Expand Down
55 changes: 30 additions & 25 deletions Mlem/Views/Tabs/Settings/Components/AccountListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down

0 comments on commit 04cd2e0

Please sign in to comment.