Refactoring

This commit is contained in:
Justin Mazzocchi 2021-01-27 18:28:12 -08:00
parent 78ab408b7c
commit 3a132889c9
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 9 additions and 15 deletions

View file

@ -6,9 +6,7 @@ import ServiceLayer
public final class IdentitiesViewModel: ObservableObject { public final class IdentitiesViewModel: ObservableObject {
public let currentIdentityId: Identity.Id public let currentIdentityId: Identity.Id
@Published public var authenticated = [Identity]() @Published public private(set) var identities = [Identity]()
@Published public var unauthenticated = [Identity]()
@Published public var pending = [Identity]()
@Published public var alertItem: AlertItem? @Published public var alertItem: AlertItem?
public let identityContext: IdentityContext public let identityContext: IdentityContext
@ -18,15 +16,8 @@ public final class IdentitiesViewModel: ObservableObject {
self.identityContext = identityContext self.identityContext = identityContext
currentIdentityId = identityContext.identity.id currentIdentityId = identityContext.identity.id
let identitiesPublisher = identityContext.service.identitiesPublisher() identityContext.service.identitiesPublisher()
.assignErrorsToAlertItem(to: \.alertItem, on: self) .assignErrorsToAlertItem(to: \.alertItem, on: self)
.share() .assign(to: &$identities)
identitiesPublisher.map { $0.filter { $0.authenticated && !$0.pending } }
.assign(to: &$authenticated)
identitiesPublisher.map { $0.filter { !$0.authenticated && !$0.pending } }
.assign(to: &$unauthenticated)
identitiesPublisher.map { $0.filter { $0.pending } }
.assign(to: &$pending)
} }
} }

View file

@ -20,9 +20,12 @@ struct IdentitiesView: View {
Label("add", systemImage: "plus.circle") Label("add", systemImage: "plus.circle")
}) })
} }
section(title: "identities.accounts", identities: viewModel.authenticated) section(title: "identities.accounts",
section(title: "identities.browsing", identities: viewModel.unauthenticated) identities: viewModel.identities.filter { $0.authenticated && !$0.pending })
section(title: "identities.pending", identities: viewModel.pending) section(title: "identities.browsing",
identities: viewModel.identities.filter { !$0.authenticated && !$0.pending })
section(title: "identities.pending",
identities: viewModel.identities.filter { $0.pending })
} }
.navigationTitle(Text("secondary-navigation.accounts")) .navigationTitle(Text("secondary-navigation.accounts"))
.toolbar { .toolbar {