[Framework] Empty and error state handling for the Feed list (#18)

This PR contains the work done to implement the handling of empty and error states for the `FeedListViewController` view controller in the `Feed` framework.

Reviewed-on: rock-n-code/app-reviews#18
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #18.
This commit is contained in:
2024-03-22 09:14:22 +00:00
committed by javier
parent d19c1c15d1
commit 050e7e9620
8 changed files with 404 additions and 39 deletions
@@ -24,6 +24,7 @@ extension FeedListViewController {
@Published var isFilterEnabled: Bool = false
@Published var isFiltering: Bool = false
@Published var isLoading: Bool = false
@Published var state: FeedListState = .initial
var items: [Review] = []
var words: [TopWord] = []
@@ -88,11 +89,14 @@ extension FeedListViewController {
items = filter == .all
? reviewsAll
: reviewsFiltered[filter] ?? []
isFilterEnabled = !items.isEmpty
state = items.isEmpty
? .empty
: .populated
} catch {
// TODO: handle this error gracefully.
print("ERROR: \(error.localizedDescription)")
items = []
state = .error
}
isLoading = false
@@ -111,7 +115,12 @@ extension FeedListViewController {
}
func item(for index: Int) -> Review? {
guard index < items.count else { return nil }
guard
!items.isEmpty,
index < items.count
else {
return nil
}
return isWordsShowing
? items[index - 1]