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

πŸ”€ :: (#661) 검색 μ „ ν™”λ©΄ λ‘œλ”© 쀑에 μ¨μΉ˜λ°” 포컀싱 μ‹œ μ•± μ’…λ£Œ 버그λ₯Ό ν•΄κ²°ν•©λ‹ˆλ‹€. #754

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import PlaylistDomainInterface
enum BeforeVcDataSoruce: Hashable {
case youtube(model: CurrentVideoEntity)
case recommend(model: RecommendPlaylistEntity)
case popularList(model: Model)

// case popularList(model: Model)
#warning("μΆ”ν›„ μ—…λ°μ΄νŠΈ μ‹œ μ‚¬μš©")
var title: String {
switch self {
case let .youtube(model):
return ""
case let .recommend(model):
return model.title
case let .popularList(model):
return model.title
// case let .popularList(model):
// return model.title
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public final class BeforeSearchReactor: Reactor {
case updateDataSource(WrapperDataSourceModel)
case updateShowRecommend(Bool)
case updateLoadingState(Bool)
case showToast(String)
}

public struct State {
var showRecommend: Bool
var isLoading: Bool
var dataSource: WrapperDataSourceModel
@Pulse var toastMessage: String?
}

init(
Expand Down Expand Up @@ -75,6 +77,8 @@ public final class BeforeSearchReactor: Reactor {
newState.showRecommend = flag
case let .updateLoadingState(isLoading):
newState.isLoading = isLoading
case let .showToast(message):
newState.toastMessage = message
}

return newState
Expand All @@ -99,8 +103,13 @@ extension BeforeSearchReactor {
fetchRecommendPlaylistUseCase
.execute()
.asObservable()
).map { Mutation.updateDataSource(WrapperDataSourceModel(currentVideo: $0.0, recommendPlayList: $0.1)) },

).map { Mutation.updateDataSource(WrapperDataSourceModel(currentVideo: $0.0, recommendPlayList: $0.1)) }
.catch { error in
let wmErorr = error.asWMError
return Observable.just(
Mutation.showToast(wmErorr.errorDescription ?? "μ•Œ 수 μ—†λŠ” 였λ₯˜κ°€ λ°œμƒν•˜μ˜€μŠ΅λ‹ˆλ‹€.")
)
},
.just(.updateLoadingState(false))
])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class ListSearchResultReactor: Reactor {
case updateDataSource(dataSource: [SearchPlaylistEntity], canLoad: Bool)
case updateLoadingState(Bool)
case updateScrollPage(Int)
case showToast(String)
}

struct State {
Expand All @@ -21,6 +22,7 @@ final class ListSearchResultReactor: Reactor {
var scrollPage: Int
var dataSource: [SearchPlaylistEntity]
var canLoad: Bool
@Pulse var toastMessage: String?
}

var initialState: State
Expand Down Expand Up @@ -65,6 +67,8 @@ final class ListSearchResultReactor: Reactor {
newState.isLoading = isLoading
case let .updateScrollPage(page):
newState.scrollPage = page
case let .showToast(message):
newState.toastMessage = message
}

return newState
Expand Down Expand Up @@ -94,6 +98,12 @@ extension ListSearchResultReactor {
.asObservable()
.map { [limit] dataSource -> Mutation in
return Mutation.updateDataSource(dataSource: prev + dataSource, canLoad: dataSource.count == limit)
}
.catch { error in
let wmErorr = error.asWMError
return Observable.just(
Mutation.showToast(wmErorr.errorDescription ?? "μ•Œ 수 μ—†λŠ” 였λ₯˜κ°€ λ°œμƒν•˜μ˜€μŠ΅λ‹ˆλ‹€.")
)
},
.just(Mutation.updateScrollPage(scrollPage + 1)),
.just(Mutation.updateLoadingState(false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class SongSearchResultReactor: Reactor {
case updateSelectedCount(Int)
case updateLoadingState(Bool)
case updateScrollPage(Int)
case showToast(String)
}

struct State {
Expand All @@ -28,6 +29,7 @@ final class SongSearchResultReactor: Reactor {
var scrollPage: Int
var dataSource: [SongEntity]
var canLoad: Bool
@Pulse var toastMessage: String?
}

var initialState: State
Expand Down Expand Up @@ -89,6 +91,9 @@ final class SongSearchResultReactor: Reactor {

case let .updateScrollPage(page):
newState.scrollPage = page

case let .showToast(message):
newState.toastMessage = message
}

return newState
Expand Down Expand Up @@ -130,6 +135,12 @@ extension SongSearchResultReactor {
.asObservable()
.map { [limit] dataSource -> Mutation in
return Mutation.updateDataSource(dataSource: prev + dataSource, canLoad: dataSource.count == limit)
}
.catch { error in
let wmErorr = error.asWMError
return Observable.just(
Mutation.showToast(wmErorr.errorDescription ?? "μ•Œ 수 μ—†λŠ” 였λ₯˜κ°€ λ°œμƒν•˜μ˜€μŠ΅λ‹ˆλ‹€.")
)
},
.just(Mutation.updateScrollPage(scrollPage + 1)), // 슀크둀 νŽ˜μ΄μ§€ 증가
.just(Mutation.updateLoadingState(false)) // λ‘œλ”© μ’…λ£Œ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ final class WakmusicRecommendReactor: Reactor {
enum Mutation {
case updateDataSource([RecommendPlaylistEntity])
case updateLodingState(Bool)
case showToast(String)
}

struct State {
var dataSource: [RecommendPlaylistEntity]
var isLoading: Bool
@Pulse var toastMessage: String?
}

func mutate(action: Action) -> Observable<Mutation> {
Expand All @@ -39,6 +41,9 @@ final class WakmusicRecommendReactor: Reactor {
newState.dataSource = dataSource
case let .updateLodingState(isLoading):
newState.isLoading = isLoading

case let .showToast(message):
newState.toastMessage = message
}

return newState
Expand All @@ -65,7 +70,13 @@ extension WakmusicRecommendReactor {
fetchRecommendPlaylistUseCase
.execute()
.asObservable()
.map { Mutation.updateDataSource($0) },
.map { Mutation.updateDataSource($0) }
.catch { error in
let wmErorr = error.asWMError
return Observable.just(
Mutation.showToast(wmErorr.errorDescription ?? "μ•Œ 수 μ—†λŠ” 였λ₯˜κ°€ λ°œμƒν•˜μ˜€μŠ΅λ‹ˆλ‹€.")
)
},
.just(.updateLodingState(false))
])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ final class PopularPlayListCell: UICollectionViewCell {
}

extension PopularPlayListCell {
public func update(_ model: Model) {
self.titleLabel.text = model.title
self.nickNameLabel.text = "Hamp"
}
#warning("μΆ”ν›„ μ—…λ°μ΄νŠΈ μ‹œ μ‚¬μš©")
// public func update(_ model: Model) {
// self.titleLabel.text = model.title
// self.nickNameLabel.text = "Hamp"
// }

private func configureUI() {
imageView.snp.makeConstraints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import RxSwift
import UIKit
import Utility

public struct Model: Hashable {
let title: String
}

final class BeforeSearchContentViewController: BaseReactorViewController<BeforeSearchReactor>, PlaylistDetailNavigator {
private let wakmusicRecommendComponent: WakmusicRecommendComponent
private let textPopUpFactory: TextPopUpFactory
Expand Down Expand Up @@ -104,6 +100,13 @@ final class BeforeSearchContentViewController: BaseReactorViewController<BeforeS

let sharedState = reactor.state.share()

reactor.pulse(\.$toastMessage)
.compactMap { $0 }
.bind(with: self) { owner, message in
owner.showToast(text: message, font: .setFont(.t6(weight: .light)))
}
.disposed(by: disposeBag)

sharedState.map(\.isLoading)
.distinctUntilChanged()
.withUnretained(self)
Expand Down Expand Up @@ -149,16 +152,16 @@ final class BeforeSearchContentViewController: BaseReactorViewController<BeforeS
}.disposed(by: disposeBag)

sharedState.map(\.dataSource)
.distinctUntilChanged { $0.currentVideo == $1.currentVideo }
.bind(with: self) { owner, dataSource in
let tmp: [Model] = [Model(title: "μž„μ‹œν”Œλ¦¬1"), Model(title: "μž„μ‹œν”Œλ¦¬2"), Model(title: "μž„μ‹œν”Œλ¦¬3")]

var snapShot = owner.dataSource.snapshot()
snapShot.appendSections([.youtube, .recommend, .popularList])
var snapShot = NSDiffableDataSourceSnapshot<BeforeSearchSection, BeforeVcDataSoruce>()
snapShot.appendSections([.youtube, .recommend])

snapShot.appendItems([.youtube(model: dataSource.currentVideo)], toSection: .youtube)
snapShot.appendItems(dataSource.recommendPlayList.map { .recommend(model: $0) }, toSection: .recommend)
snapShot.appendItems(tmp.map { .popularList(model: $0) }, toSection: .popularList)

#warning("μΆ”ν›„ μ—…λ°μ΄νŠΈ μ‹œ μ‚¬μš©")
// snapShot.appendItems(tmp.map { .popularList(model: $0) }, toSection: .popularList)

owner.dataSource.apply(snapShot, animatingDifferences: false)
}
Expand Down Expand Up @@ -240,11 +243,12 @@ extension BeforeSearchContentViewController {
cell.update(model: itemIdentifier)
}

let popularListCellRegistration = UICollectionView
.CellRegistration<PopularPlayListCell, Model> { cell, indexPath, item in

cell.update(item)
}
#warning("μΆ”ν›„ μ—…λ°μ΄νŠΈ μ‹œ μ‚¬μš©")
// let popularListCellRegistration = UICollectionView
// .CellRegistration<PopularPlayListCell, Model> { cell, indexPath, item in
//
// cell.update(item)
// }

// MARK: Header

Expand Down Expand Up @@ -284,12 +288,14 @@ extension BeforeSearchContentViewController {
item: model
)

case let .popularList(model: model):
return collectionView.dequeueConfiguredReusableCell(
using: popularListCellRegistration,
for: indexPath,
item: model
)
// case let .popularList(model: model):
// break
#warning("μΆ”ν›„ μ—…λ°μ΄νŠΈ μ‹œ μ‚¬μš©")
// return collectionView.dequeueConfiguredReusableCell(
// using: popularListCellRegistration,
// for: indexPath,
// item: model
// )
}
}

Expand All @@ -301,7 +307,7 @@ extension BeforeSearchContentViewController {
}
}

// MARK: CollectionView Deleagte
// MARK: CollectionView Deleagate
extension BeforeSearchContentViewController: UICollectionViewDelegate {
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let model = dataSource.itemIdentifier(for: indexPath) else {
Expand All @@ -316,8 +322,9 @@ extension BeforeSearchContentViewController: UICollectionViewDelegate {

navigatePlaylistDetail(key: model.key, kind: .wakmu)

case let .popularList(model: model):
LogManager.printDebug("popular \(model)")
#warning("μΆ”ν›„ μ—…λ°μ΄νŠΈ μ‹œ μ‚¬μš©")
// case let .popularList(model: model):
// LogManager.printDebug("popular \(model)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ final class ListSearchResultViewController: BaseReactorViewController<ListSearch

let sharedState = reactor.state.share()

reactor.pulse(\.$toastMessage)
.compactMap { $0 }
.bind(with: self) { owner, message in
owner.showToast(text: message, font: .setFont(.t6(weight: .light)))
}
.disposed(by: disposeBag)

sharedState.map(\.sortType)
.distinctUntilChanged()
.bind(with: self) { owner, type in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ final class SongSearchResultViewController: BaseReactorViewController<SongSearch

let sharedState = reactor.state.share()

reactor.pulse(\.$toastMessage)
.compactMap { $0 }
.bind(with: self) { owner, message in
owner.showToast(text: message, font: .setFont(.t6(weight: .light)))
}
.disposed(by: disposeBag)

sharedState.map(\.sortType)
.distinctUntilChanged()
.bind(with: self) { owner, type in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ final class WakmusicRecommendViewController: BaseReactorViewController<WakmusicR
super.bindState(reactor: reactor)
let sharedState = reactor.state.share()

reactor.pulse(\.$toastMessage)
.compactMap { $0 }
.bind(with: self) { owner, message in
owner.showToast(text: message, font: .setFont(.t6(weight: .light)))
}
.disposed(by: disposeBag)

sharedState.map(\.dataSource)
.distinctUntilChanged()
.withUnretained(self)
Expand Down
Loading