From 3a132889c91fff2ed075d5b8e251575a50e1900e Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Wed, 27 Jan 2021 18:28:12 -0800 Subject: [PATCH] Refactoring --- .../View Models/IdentitiesViewModel.swift | 15 +++------------ Views/IdentitiesView.swift | 9 ++++++--- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/ViewModels/Sources/ViewModels/View Models/IdentitiesViewModel.swift b/ViewModels/Sources/ViewModels/View Models/IdentitiesViewModel.swift index 0b6c96f..bcfef46 100644 --- a/ViewModels/Sources/ViewModels/View Models/IdentitiesViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/IdentitiesViewModel.swift @@ -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) } } diff --git a/Views/IdentitiesView.swift b/Views/IdentitiesView.swift index ad3461e..aee8d03 100644 --- a/Views/IdentitiesView.swift +++ b/Views/IdentitiesView.swift @@ -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 {