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 let currentIdentityId: Identity.Id
@Published public var authenticated = [Identity]()
@Published public var unauthenticated = [Identity]()
@Published public var pending = [Identity]()
@Published public private(set) var identities = [Identity]()
@Published public var alertItem: AlertItem?
public let identityContext: IdentityContext
@ -18,15 +16,8 @@ public final class IdentitiesViewModel: ObservableObject {
self.identityContext = identityContext
currentIdentityId = identityContext.identity.id
let identitiesPublisher = identityContext.service.identitiesPublisher()
identityContext.service.identitiesPublisher()
.assignErrorsToAlertItem(to: \.alertItem, on: self)
.share()
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)
.assign(to: &$identities)
}
}

View File

@ -20,9 +20,12 @@ struct IdentitiesView: View {
Label("add", systemImage: "plus.circle")
})
}
section(title: "identities.accounts", identities: viewModel.authenticated)
section(title: "identities.browsing", identities: viewModel.unauthenticated)
section(title: "identities.pending", identities: viewModel.pending)
section(title: "identities.accounts",
identities: viewModel.identities.filter { $0.authenticated && !$0.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"))
.toolbar {