Skip to content

Commit

Permalink
fix(View Active Critters): display all lists when all have been captu…
Browse files Browse the repository at this point in the history
…red (Dimillian#322)

* Previously it displayed a Loading View
* Fix Dimillian#321
  • Loading branch information
renaudjenny authored Sep 24, 2020
1 parent bbd5a1b commit 12a051c
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ class ActiveCrittersViewModel: ObservableObject {
}

@Published var crittersInfo: [CritterType: CritterInfo] = [:]
@Published var isLoading: Bool

private let items: Items
private let collection: UserCollection
@@ -54,10 +55,12 @@ class ActiveCrittersViewModel: ObservableObject {
init(filterOutInCollection: Bool = false, items: Items = .shared, collection: UserCollection = .shared) {
self.items = items
self.collection = collection
self.isLoading = true

cancellable = Publishers.CombineLatest(items.$categories, collection.$critters)
.receive(on: DispatchQueue.main)
.sink { [weak self] (items, critters) in
guard let self = self else { return }
for type in CritterType.allCases {
var active = items[type.category()]?.filterActiveThisMonth() ?? []
var new = active.filter{ $0.isNewThisMonth() }
@@ -72,12 +75,13 @@ class ActiveCrittersViewModel: ObservableObject {
active = active.filter{ !critters.contains($0) }
}

self?.crittersInfo[type] = CritterInfo(active: active,
self.crittersInfo[type] = CritterInfo(active: active,
new: new,
leaving: leaving,
caught: caught,
toCatchNow: toCatchNow,
toCatchLater: toCatchLater)
self.isLoading = false
}
}
}
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ struct ActiveCrittersView: View {

private func makeList(type: ActiveCrittersViewModel.CritterType) -> some View {
List {
if viewModel.crittersInfo[type]?.active.isEmpty == true {
if viewModel.isLoading == true {
RowLoadingView()
} else {
ActiveCritterSections(viewModel: viewModel,

0 comments on commit 12a051c

Please sign in to comment.