feat(content-all): theme, 정렬(최신순/인기순) 추가
This commit is contained in:
@@ -20,6 +20,44 @@ struct ContentAllView: View {
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: isFree ? "무료 콘텐츠 전체" : isPointAvailableOnly ? "포인트 대여 전체" : "콘텐츠 전체")
|
||||
|
||||
if !viewModel.themeList.isEmpty {
|
||||
ContentMainContentThemeView(
|
||||
themeList: viewModel.themeList,
|
||||
selectTheme: viewModel.selectTheme,
|
||||
selectedTheme: $viewModel.selectedTheme
|
||||
)
|
||||
}
|
||||
|
||||
HStack(spacing: 12) {
|
||||
Spacer()
|
||||
|
||||
Text("최신순")
|
||||
.font(.custom(Font.preMedium.rawValue, size: 16))
|
||||
.foregroundColor(
|
||||
Color(hex: "e2e2e2")
|
||||
.opacity(viewModel.sort == .NEWEST ? 1 : 0.5)
|
||||
)
|
||||
.onTapGesture {
|
||||
if viewModel.sort != .NEWEST {
|
||||
viewModel.sort = .NEWEST
|
||||
}
|
||||
}
|
||||
|
||||
Text("인기순")
|
||||
.font(.custom(Font.preMedium.rawValue, size: 16))
|
||||
.foregroundColor(
|
||||
Color(hex: "e2e2e2")
|
||||
.opacity(viewModel.sort == .POPULARITY ? 1 : 0.5)
|
||||
)
|
||||
.onTapGesture {
|
||||
if viewModel.sort != .POPULARITY {
|
||||
viewModel.sort = .POPULARITY
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 12)
|
||||
.padding(.horizontal, 24)
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
let horizontalPadding: CGFloat = 24
|
||||
let gridSpacing: CGFloat = 16
|
||||
@@ -95,6 +133,7 @@ struct ContentAllView: View {
|
||||
.onAppear {
|
||||
viewModel.isFree = isFree
|
||||
viewModel.isPointAvailableOnly = isPointAvailableOnly
|
||||
viewModel.getThemeList()
|
||||
viewModel.fetchData()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ import Foundation
|
||||
import Combine
|
||||
|
||||
final class ContentAllViewModel: ObservableObject {
|
||||
enum Sort: String {
|
||||
case NEWEST, POPULARITY
|
||||
}
|
||||
|
||||
private let repository = ContentRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@@ -16,11 +20,30 @@ final class ContentAllViewModel: ObservableObject {
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var themeList = [String]()
|
||||
@Published var contentList = [AudioContentMainItem]()
|
||||
|
||||
@Published var sort = Sort.NEWEST {
|
||||
didSet {
|
||||
page = 1
|
||||
isLast = false
|
||||
contentList.removeAll()
|
||||
fetchData()
|
||||
}
|
||||
}
|
||||
|
||||
@Published var selectedTheme = "전체" {
|
||||
didSet {
|
||||
page = 1
|
||||
isLast = false
|
||||
contentList.removeAll()
|
||||
fetchData()
|
||||
}
|
||||
}
|
||||
|
||||
var page = 1
|
||||
var isLast = false
|
||||
private let pageSize = 10
|
||||
private let pageSize = 20
|
||||
|
||||
var isFree: Bool = false
|
||||
var isPointAvailableOnly: Bool = false
|
||||
@@ -29,7 +52,7 @@ final class ContentAllViewModel: ObservableObject {
|
||||
if !isLast && !isLoading {
|
||||
isLoading = true
|
||||
|
||||
repository.getAllAudioContents(page: page, size: pageSize, isFree: isFree, isPointAvailableOnly: isPointAvailableOnly)
|
||||
repository.getAllAudioContents(page: page, size: pageSize, isFree: isFree, isPointAvailableOnly: isPointAvailableOnly, sortType: sort, theme: selectedTheme == "전체" ? nil : selectedTheme)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
@@ -75,4 +98,48 @@ final class ContentAllViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
||||
func getThemeList() {
|
||||
repository.getAudioContentActiveThemeList(isFree: isFree, isPointAvailableOnly: isPointAvailableOnly)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<[String]>.self, from: responseData)
|
||||
self.isLoading = false
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.themeList = ["전체"] + data
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
self.isLoading = false
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func selectTheme(theme: String) {
|
||||
if selectedTheme != theme {
|
||||
selectedTheme = theme
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user