diff --git a/Frameworks/Feed/Bundle/Sources/Logic/Enumerations/FeedListState.swift b/Frameworks/Feed/Bundle/Sources/Logic/Enumerations/FeedListState.swift new file mode 100644 index 0000000..1f177ee --- /dev/null +++ b/Frameworks/Feed/Bundle/Sources/Logic/Enumerations/FeedListState.swift @@ -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 +} diff --git a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift index 08671b7..c561eac 100644 --- a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift +++ b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift @@ -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] diff --git a/Reviews.xcodeproj/project.pbxproj b/Reviews.xcodeproj/project.pbxproj index 19b080a..0a47e76 100644 --- a/Reviews.xcodeproj/project.pbxproj +++ b/Reviews.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 028134712BACC8CC0074AB4B /* FeedListConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134702BACC8CC0074AB4B /* FeedListConfiguration.swift */; }; 028134822BACCC780074AB4B /* FeedListCoordination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 028134812BACCC770074AB4B /* FeedListCoordination.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 */; }; 02909E792BAB6B0200710E14 /* FilterOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02909E782BAB6B0200710E14 /* FilterOption.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 = ""; }; 028134812BACCC770074AB4B /* FeedListCoordination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListCoordination.swift; sourceTree = ""; }; 028134832BACD0B20074AB4B /* FeedItemCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedItemCoordinator.swift; sourceTree = ""; }; + 028134872BAD01A60074AB4B /* FeedListState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListState.swift; sourceTree = ""; }; 028134892BAD08AB0074AB4B /* FeedUnavailableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedUnavailableView.swift; sourceTree = ""; }; 02909E782BAB6B0200710E14 /* FilterOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterOption.swift; sourceTree = ""; }; 02909E7A2BAB6D2E00710E14 /* Bundle+Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Constants.swift"; sourceTree = ""; }; @@ -203,6 +205,7 @@ 02909E772BAB6AD500710E14 /* Enumerations */ = { isa = PBXGroup; children = ( + 028134872BAD01A60074AB4B /* FeedListState.swift */, 02909E782BAB6B0200710E14 /* FilterOption.swift */, ); path = Enumerations; @@ -512,6 +515,7 @@ 02EACF322BABB23A00FF8ECD /* TopWordsView.swift in Sources */, 028134712BACC8CC0074AB4B /* FeedListConfiguration.swift in Sources */, 028134822BACCC780074AB4B /* FeedListCoordination.swift in Sources */, + 028134882BAD01A60074AB4B /* FeedListState.swift in Sources */, 02909E792BAB6B0200710E14 /* FilterOption.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0;