feat(content): 추천 전체보기를 연결한다
This commit is contained in:
@@ -23,7 +23,7 @@ final class MainContentAllViewModel: ObservableObject {
|
||||
@Published var isShowPopup = false
|
||||
|
||||
var allowedSorts: [ContentSort] {
|
||||
selectedType == .free ? [.latest, .popular] : ContentSort.allCases
|
||||
allowedSorts(for: selectedType)
|
||||
}
|
||||
|
||||
var shouldShowEmptyState: Bool {
|
||||
@@ -40,6 +40,19 @@ final class MainContentAllViewModel: ObservableObject {
|
||||
fetchContents(page: 0, isNextPage: false)
|
||||
}
|
||||
|
||||
func apply(type: MainContentAllType, sort: ContentSort) {
|
||||
guard allowedSorts(for: type).contains(sort) else { return }
|
||||
|
||||
if selectedType == type, selectedSort == sort, hasLoaded {
|
||||
return
|
||||
}
|
||||
|
||||
selectedType = type
|
||||
selectedSort = sort
|
||||
clearItems()
|
||||
fetchFirstPage()
|
||||
}
|
||||
|
||||
func selectType(_ type: MainContentAllType) {
|
||||
guard selectedType != type else { return }
|
||||
|
||||
@@ -77,6 +90,10 @@ final class MainContentAllViewModel: ObservableObject {
|
||||
fetchNextPageIfPossible()
|
||||
}
|
||||
|
||||
private func allowedSorts(for type: MainContentAllType) -> [ContentSort] {
|
||||
type == .free ? [.latest, .popular] : ContentSort.allCases
|
||||
}
|
||||
|
||||
private func fetchNextPageIfPossible() {
|
||||
guard hasNext, isLoading == false, isLoadingNextPage == false else { return }
|
||||
fetchContents(page: page + 1, isNextPage: true)
|
||||
|
||||
Reference in New Issue
Block a user