Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ :: (#1148) ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ๋กœ๋”ฉ ์ค‘ ํ•„ํ„ฐ๋‚˜ ์ •๋ ฌ์„ ๋ˆ„๋ฅผ ๋•Œ ์•ฑ์ด ํ„ฐ์ง€๋Š” ๋ฒ„๊ทธ #1151

Merged
merged 10 commits into from
Aug 16, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,16 @@ extension ListSearchResultReactor {
private func updateSortType(_ type: SortType) -> Observable<Mutation> {
return .concat([
.just(.updateSortType(type)),
updateDataSource(order: type, text: self.text, scrollPage: 1, byOption: true)
updateDataSource(order: type, text: self.text, scrollPage: 1)
])
}

private func updateDataSource(
order: SortType,
text: String,
scrollPage: Int,
byOption: Bool = false // ํ•„ํ„ฐ๋˜๋Š” ์˜ต์…˜์œผ๋กœ ๋ฆฌํ”„๋ž˜์‰ฌ ํ•˜๋‚˜ , ์•„๋‹ˆ๋ฉด ์Šคํฌ๋กค์ด๋ƒ
scrollPage: Int
) -> Observable<Mutation> {
let prev: [SearchPlaylistEntity] = byOption ? [] : self.currentState.dataSource
let prev: [SearchPlaylistEntity] = scrollPage == 1 ? [] : self.currentState.dataSource

return .concat([
.just(Mutation.updateLoadingState(true)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extension SongSearchResultReactor {
return .concat([
.just(.updateSelectedCount(0)),
.just(.updateSortType(type)),
updateDataSource(order: type, filter: state.filterType, text: self.text, scrollPage: 1, byOption: true)
updateDataSource(order: type, filter: state.filterType, text: self.text, scrollPage: 1)
])
}

Expand All @@ -131,16 +131,15 @@ extension SongSearchResultReactor {
return .concat([
.just(.updateSelectedCount(0)),
.just(.updateFilterType(type)),
updateDataSource(order: state.sortType, filter: type, text: self.text, scrollPage: 1, byOption: true)
updateDataSource(order: state.sortType, filter: type, text: self.text, scrollPage: 1)
])
}

private func updateDataSource(
order: SortType,
filter: FilterType,
text: String,
scrollPage: Int,
byOption: Bool = false // ํ•„ํ„ฐ๋˜๋Š” ์˜ต์…˜์œผ๋กœ ๋ฆฌํ”„๋ž˜์‰ฌ ํ•˜๋‚˜ , ์•„๋‹ˆ๋ฉด ์Šคํฌ๋กค์ด๋ƒ
scrollPage: Int
) -> Observable<Mutation> {
return .concat([
.just(.updateLoadingState(true)),
Expand All @@ -151,7 +150,7 @@ extension SongSearchResultReactor {

guard let self else { return .updateDataSource(dataSource: [], canLoad: false) }

let prev: [SongEntity] = byOption ? [] : self.currentState.dataSource
let prev: [SongEntity] = scrollPage == 1 ? [] : self.currentState.dataSource

if scrollPage == 1 {
LogManager.analytics(SearchAnalyticsLog.viewSearchResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class ListSearchResultViewController: BaseReactorViewController<ListSearch

private lazy var collectionView: UICollectionView = createCollectionView().then {
$0.backgroundColor = DesignSystemAsset.BlueGrayColor.gray100.color
$0.bounces = false
$0.isHidden = true
}

private lazy var headerView: SearchOptionHeaderView = SearchOptionHeaderView(false)
Expand Down Expand Up @@ -122,32 +122,36 @@ final class ListSearchResultViewController: BaseReactorViewController<ListSearch
}
.disposed(by: disposeBag)

sharedState.map { ($0.isLoading, $0.dataSource) }
.bind(with: self) { owner, info in

let (isLoading, dataSource) = (info.0, info.1)
sharedState.map(\.isLoading)
.bind(with: self) { owner, isLoading in

if isLoading {
owner.indicator.startAnimating()
} else {
owner.collectionView.isHidden = false
owner.indicator.stopAnimating()
}
}
.disposed(by: disposeBag)

var snapshot = NSDiffableDataSourceSnapshot<ListSearchResultSection, SearchPlaylistEntity>()
sharedState.map(\.dataSource)
.bind(with: self) { owner, dataSource in

snapshot.appendSections([.list])
var snapshot = NSDiffableDataSourceSnapshot<ListSearchResultSection, SearchPlaylistEntity>()

snapshot.appendItems(dataSource, toSection: .list)
owner.dataSource.apply(snapshot, animatingDifferences: false)
snapshot.appendSections([.list])

let warningView = WMWarningView(
text: "๊ฒ€์ƒ‰๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."
)
snapshot.appendItems(dataSource, toSection: .list)
owner.dataSource.apply(snapshot, animatingDifferences: false)

if dataSource.isEmpty {
owner.collectionView.setBackgroundView(warningView, 100)
} else {
owner.collectionView.restore()
}
let warningView = WMWarningView(
text: "๊ฒ€์ƒ‰๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."
)

if dataSource.isEmpty {
owner.collectionView.setBackgroundView(warningView, 100)
} else {
owner.collectionView.restore()
}
}
.disposed(by: disposeBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ final class SongSearchResultViewController: BaseReactorViewController<SongSearch
.disposed(by: disposeBag)

sharedState.map { $0.dataSource }
.distinctUntilChanged()
.bind(with: self) { owner, dataSource in

var snapshot = NSDiffableDataSourceSnapshot<SongSearchResultSection, SongEntity>()

snapshot.appendSections([.song])
Expand Down
Loading