mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01:00 +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 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue