diff --git a/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/VC/HomeVC.swift b/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/VC/HomeVC.swift index b8527c30..2cb3895f 100644 --- a/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/VC/HomeVC.swift +++ b/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/VC/HomeVC.swift @@ -113,6 +113,7 @@ private extension HomeVC { self.navigationItem.backBarButtonItem = backBarButtonItem homeSearchView.isHidden = true + homeListView.hideEmptyView() } func setupLayout() { @@ -156,16 +157,10 @@ private extension HomeVC { viewModel.state .map(\.travelList) - .dropFirst() .removeDuplicates() .withUnretained(self) .sink { owner, list in owner.homeListView.setupData(list: list) - if list.isEmpty { - owner.homeListView.showEmptyView() - } else { - owner.homeListView.hideEmptyView() - } } .store(in: &cancellables) @@ -254,6 +249,18 @@ private extension HomeVC { owner.navigationController?.pushViewController(travelVC, animated: true) } .store(in: &cancellables) + + viewModel.state + .map(\.isEmptyResult) + .withUnretained(self) + .sink { owner, isEmpty in + if isEmpty { + owner.homeListView.showEmptyView() + } else { + owner.homeListView.hideEmptyView() + } + } + .store(in: &cancellables) } func bindListView() { diff --git a/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/ViewModel/HomeState.swift b/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/ViewModel/HomeState.swift index f890b402..7f46da42 100644 --- a/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/ViewModel/HomeState.swift +++ b/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/ViewModel/HomeState.swift @@ -27,6 +27,7 @@ struct HomeState: BaseState { var resultFilters: FilterDictionary = .make() var curFilter: Filter? = .emtpy var moveToTravelWriting: Bool = false + var isEmptyResult: Bool = false var isSearching: Bool { homeViewType == .recent || homeViewType == .related diff --git a/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/ViewModel/HomeViewModel.swift b/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/ViewModel/HomeViewModel.swift index 68515435..853f57d7 100644 --- a/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/ViewModel/HomeViewModel.swift +++ b/iOS/traveline/Sources/Feature/HomeFeature/HomeScene/ViewModel/HomeViewModel.swift @@ -90,6 +90,7 @@ final class HomeViewModel: BaseViewModel newState.travelList = searchResult.travelList newState.homeViewType = .result newState.resultFilters = .make() + newState.isEmptyResult = searchResult.travelList.isEmpty newState.searchQuery = .init( keyword: searchResult.keyword, offset: 2 @@ -99,10 +100,12 @@ final class HomeViewModel: BaseViewModel newState.travelList = travelList newState.searchQuery.offset = 2 newState.searchQuery.keyword = nil + newState.isEmptyResult = travelList.isEmpty case let .showNewList(travelList): newState.travelList = travelList newState.searchQuery.offset = 2 + newState.isEmptyResult = travelList.isEmpty case let .showFilter(type): newState.curFilter = (state.homeViewType == .home) ? state.homeFilters[type] : state.resultFilters[type]