Skip to content

Commit

Permalink
set flow before dismissals
Browse files Browse the repository at this point in the history
  • Loading branch information
mormaer committed Sep 17, 2023
1 parent ed76da2 commit b457d51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
20 changes: 9 additions & 11 deletions Mlem/Views/Shared/Accounts/Accounts Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ struct AccountsPage: View {
Section(header: Text(instance)) {
ForEach(accountsTracker.accountsByInstance[instance] ?? []) { account in
Button(account.nickname) {
dismiss()
setFlow(using: account)
dismiss()
}
.disabled(isActiveAccount(account))
.swipeActions {
Button("Remove", role: .destructive) {
dismiss()
accountsTracker.removeAccount(account: account)
if account == appState.currentActiveAccount {
if isActiveAccount(account) {
// if we just deleted the current account we (currently!) have a decision to make
if let first = accountsTracker.savedAccounts.first {
// if we have another account available, go to that...
Expand All @@ -55,6 +54,8 @@ struct AccountsPage: View {
// no accounts, so go to onboarding
setFlow(using: nil)
}

dismiss()
}
}
}
Expand Down Expand Up @@ -100,14 +101,11 @@ struct AccountsPage: View {
}

private func setFlow(using account: SavedAccount?) {
// this tiny delay prevents the modal dismiss animation from being cancelled
DispatchQueue.main.asyncAfter(deadline: .now() + 0.03) {
if let account {
setFlow(.account(account))
return
}

setFlow(.onboarding)
if let account {
setFlow(.account(account))
return
}

setFlow(.onboarding)
}
}
7 changes: 3 additions & 4 deletions Mlem/Views/Shared/Accounts/Add Account View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct AddSavedInstanceView: View {
}
}
.navigationTitle(Text(onboarding ? "Log in" : ""))
.navigationBarTitleDisplayMode(.inline)
}

var isReadyToSubmit: Bool {
Expand Down Expand Up @@ -331,13 +332,11 @@ struct AddSavedInstanceView: View {
AppConstants.keychain["\(newAccount.id)_accessToken"] = response.jwt
accountsTracker.addAccount(account: newAccount)

setFlow(.account(newAccount))

if !onboarding {
dismiss()
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
setFlow(.account(newAccount))
}
} catch {
handle(error)
}
Expand Down
4 changes: 0 additions & 4 deletions Mlem/Views/Shared/Accounts/Instance Picker View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ struct InstancePickerView: View {
var body: some View {
ScrollView {
LazyVStack(spacing: 0) {
// Text("Instances")
// .bold()
// .padding()

if onboarding {
Text(pickInstance)
.frame(maxWidth: .infinity)
Expand Down

0 comments on commit b457d51

Please sign in to comment.