Added the "state" property to the FeedListViewModel view model in the Feed framework.
This commit is contained in:
parent
b9a3b51759
commit
8eae96e404
@ -0,0 +1,14 @@
|
|||||||
|
//
|
||||||
|
// FeedListState.swift
|
||||||
|
// ReviewsFeed
|
||||||
|
//
|
||||||
|
// Created by Javier Cicchelli on 22/03/2024.
|
||||||
|
// Copyright © 2024 Röck+Cöde. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
enum FeedListState {
|
||||||
|
case empty
|
||||||
|
case error
|
||||||
|
case initial
|
||||||
|
case populated
|
||||||
|
}
|
@ -24,6 +24,7 @@ extension FeedListViewController {
|
|||||||
@Published var isFilterEnabled: Bool = false
|
@Published var isFilterEnabled: Bool = false
|
||||||
@Published var isFiltering: Bool = false
|
@Published var isFiltering: Bool = false
|
||||||
@Published var isLoading: Bool = false
|
@Published var isLoading: Bool = false
|
||||||
|
@Published var state: FeedListState = .initial
|
||||||
|
|
||||||
var items: [Review] = []
|
var items: [Review] = []
|
||||||
var words: [TopWord] = []
|
var words: [TopWord] = []
|
||||||
@ -88,11 +89,14 @@ extension FeedListViewController {
|
|||||||
items = filter == .all
|
items = filter == .all
|
||||||
? reviewsAll
|
? reviewsAll
|
||||||
: reviewsFiltered[filter] ?? []
|
: reviewsFiltered[filter] ?? []
|
||||||
|
|
||||||
isFilterEnabled = !items.isEmpty
|
isFilterEnabled = !items.isEmpty
|
||||||
|
state = items.isEmpty
|
||||||
|
? .empty
|
||||||
|
: .populated
|
||||||
} catch {
|
} catch {
|
||||||
// TODO: handle this error gracefully.
|
items = []
|
||||||
print("ERROR: \(error.localizedDescription)")
|
state = .error
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoading = false
|
isLoading = false
|
||||||
@ -111,7 +115,12 @@ extension FeedListViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func item(for index: Int) -> Review? {
|
func item(for index: Int) -> Review? {
|
||||||
guard index < items.count else { return nil }
|
guard
|
||||||
|
!items.isEmpty,
|
||||||
|
index < items.count
|
||||||
|
else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return isWordsShowing
|
return isWordsShowing
|
||||||
? items[index - 1]
|
? items[index - 1]
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
028134712BACC8CC0074AB4B /* FeedListConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134702BACC8CC0074AB4B /* FeedListConfiguration.swift */; };
|
028134712BACC8CC0074AB4B /* FeedListConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134702BACC8CC0074AB4B /* FeedListConfiguration.swift */; };
|
||||||
028134822BACCC780074AB4B /* FeedListCoordination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134812BACCC770074AB4B /* FeedListCoordination.swift */; };
|
028134822BACCC780074AB4B /* FeedListCoordination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134812BACCC770074AB4B /* FeedListCoordination.swift */; };
|
||||||
028134842BACD0B20074AB4B /* FeedItemCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134832BACD0B20074AB4B /* FeedItemCoordinator.swift */; };
|
028134842BACD0B20074AB4B /* FeedItemCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134832BACD0B20074AB4B /* FeedItemCoordinator.swift */; };
|
||||||
|
028134882BAD01A60074AB4B /* FeedListState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134872BAD01A60074AB4B /* FeedListState.swift */; };
|
||||||
0281348A2BAD08AB0074AB4B /* FeedUnavailableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134892BAD08AB0074AB4B /* FeedUnavailableView.swift */; };
|
0281348A2BAD08AB0074AB4B /* FeedUnavailableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134892BAD08AB0074AB4B /* FeedUnavailableView.swift */; };
|
||||||
02909E792BAB6B0200710E14 /* FilterOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02909E782BAB6B0200710E14 /* FilterOption.swift */; };
|
02909E792BAB6B0200710E14 /* FilterOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02909E782BAB6B0200710E14 /* FilterOption.swift */; };
|
||||||
02909E7B2BAB6D2E00710E14 /* Bundle+Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02909E7A2BAB6D2E00710E14 /* Bundle+Constants.swift */; };
|
02909E7B2BAB6D2E00710E14 /* Bundle+Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02909E7A2BAB6D2E00710E14 /* Bundle+Constants.swift */; };
|
||||||
@ -69,6 +70,7 @@
|
|||||||
028134702BACC8CC0074AB4B /* FeedListConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListConfiguration.swift; sourceTree = "<group>"; };
|
028134702BACC8CC0074AB4B /* FeedListConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListConfiguration.swift; sourceTree = "<group>"; };
|
||||||
028134812BACCC770074AB4B /* FeedListCoordination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListCoordination.swift; sourceTree = "<group>"; };
|
028134812BACCC770074AB4B /* FeedListCoordination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListCoordination.swift; sourceTree = "<group>"; };
|
||||||
028134832BACD0B20074AB4B /* FeedItemCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedItemCoordinator.swift; sourceTree = "<group>"; };
|
028134832BACD0B20074AB4B /* FeedItemCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedItemCoordinator.swift; sourceTree = "<group>"; };
|
||||||
|
028134872BAD01A60074AB4B /* FeedListState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListState.swift; sourceTree = "<group>"; };
|
||||||
028134892BAD08AB0074AB4B /* FeedUnavailableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedUnavailableView.swift; sourceTree = "<group>"; };
|
028134892BAD08AB0074AB4B /* FeedUnavailableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedUnavailableView.swift; sourceTree = "<group>"; };
|
||||||
02909E782BAB6B0200710E14 /* FilterOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterOption.swift; sourceTree = "<group>"; };
|
02909E782BAB6B0200710E14 /* FilterOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterOption.swift; sourceTree = "<group>"; };
|
||||||
02909E7A2BAB6D2E00710E14 /* Bundle+Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Constants.swift"; sourceTree = "<group>"; };
|
02909E7A2BAB6D2E00710E14 /* Bundle+Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Constants.swift"; sourceTree = "<group>"; };
|
||||||
@ -203,6 +205,7 @@
|
|||||||
02909E772BAB6AD500710E14 /* Enumerations */ = {
|
02909E772BAB6AD500710E14 /* Enumerations */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
028134872BAD01A60074AB4B /* FeedListState.swift */,
|
||||||
02909E782BAB6B0200710E14 /* FilterOption.swift */,
|
02909E782BAB6B0200710E14 /* FilterOption.swift */,
|
||||||
);
|
);
|
||||||
path = Enumerations;
|
path = Enumerations;
|
||||||
@ -512,6 +515,7 @@
|
|||||||
02EACF322BABB23A00FF8ECD /* TopWordsView.swift in Sources */,
|
02EACF322BABB23A00FF8ECD /* TopWordsView.swift in Sources */,
|
||||||
028134712BACC8CC0074AB4B /* FeedListConfiguration.swift in Sources */,
|
028134712BACC8CC0074AB4B /* FeedListConfiguration.swift in Sources */,
|
||||||
028134822BACCC780074AB4B /* FeedListCoordination.swift in Sources */,
|
028134822BACCC780074AB4B /* FeedListCoordination.swift in Sources */,
|
||||||
|
028134882BAD01A60074AB4B /* FeedListState.swift in Sources */,
|
||||||
02909E792BAB6B0200710E14 /* FilterOption.swift in Sources */,
|
02909E792BAB6B0200710E14 /* FilterOption.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user