Skip to content

Commit

Permalink
chore #384: 검색 결과 엠티뷰 생성 주기 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolz committed Jan 15, 2024
1 parent afec520 commit 7480120
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private extension HomeVC {
self.navigationItem.backBarButtonItem = backBarButtonItem

homeSearchView.isHidden = true
homeListView.hideEmptyView()
}

func setupLayout() {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ final class HomeViewModel: BaseViewModel<HomeAction, HomeSideEffect, HomeState>
newState.travelList = searchResult.travelList
newState.homeViewType = .result
newState.resultFilters = .make()
newState.isEmptyResult = searchResult.travelList.isEmpty
newState.searchQuery = .init(
keyword: searchResult.keyword,
offset: 2
Expand All @@ -99,10 +100,12 @@ final class HomeViewModel: BaseViewModel<HomeAction, HomeSideEffect, HomeState>
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]
Expand Down

0 comments on commit 7480120

Please sign in to comment.