mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-22 05:26:30 +00:00
Refactoring
This commit is contained in:
parent
78ab408b7c
commit
3a132889c9
2 changed files with 9 additions and 15 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue