큐레이션 전체보기 페이지 추가
This commit is contained in:
105
SodaLive/Sources/Content/Curation/ContentCurationView.swift
Normal file
105
SodaLive/Sources/Content/Curation/ContentCurationView.swift
Normal file
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// ContentCurationView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/09/27.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentCurationView: View {
|
||||
|
||||
@StateObject var viewModel = ContentCurationViewModel()
|
||||
|
||||
let title: String
|
||||
let curationId: Int
|
||||
|
||||
let columns = [
|
||||
GridItem(.flexible()),
|
||||
GridItem(.flexible())
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: title)
|
||||
|
||||
HStack(spacing: 13.3) {
|
||||
Spacer()
|
||||
|
||||
Text("최신순")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(
|
||||
Color(hex: "e2e2e2")
|
||||
.opacity(viewModel.sort == .NEWEST ? 1 : 0.5)
|
||||
)
|
||||
.onTapGesture {
|
||||
if viewModel.sort != .NEWEST {
|
||||
viewModel.sort = .NEWEST
|
||||
}
|
||||
}
|
||||
|
||||
Text("높은 가격순")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(
|
||||
Color(hex: "e2e2e2")
|
||||
.opacity(viewModel.sort == .PRICE_HIGH ? 1 : 0.5)
|
||||
)
|
||||
.onTapGesture {
|
||||
if viewModel.sort != .PRICE_HIGH {
|
||||
viewModel.sort = .PRICE_HIGH
|
||||
}
|
||||
}
|
||||
|
||||
Text("낮은 가격순")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(
|
||||
Color(hex: "e2e2e2")
|
||||
.opacity(viewModel.sort == .PRICE_LOW ? 1 : 0.5)
|
||||
)
|
||||
.onTapGesture {
|
||||
if viewModel.sort != .PRICE_LOW {
|
||||
viewModel.sort = .PRICE_LOW
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 13.3)
|
||||
.padding(.horizontal, 20)
|
||||
.background(Color(hex: "161616"))
|
||||
.padding(.top, 13.3)
|
||||
|
||||
HStack(spacing: 0) {
|
||||
Text("전체")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "e2e2e2"))
|
||||
|
||||
Text("\(viewModel.totalCount)")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "ff5c49"))
|
||||
.padding(.leading, 8)
|
||||
|
||||
Text("개")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "e2e2e2"))
|
||||
.padding(.leading, 2)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.vertical, 13.3)
|
||||
.padding(.horizontal, 20)
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
LazyVGrid(columns: columns, spacing: 13.3) {
|
||||
ForEach(0..<viewModel.contentList.count, id: \.self) {
|
||||
ContentNewAllItemView(item: viewModel.contentList[$0])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.curationId = curationId
|
||||
viewModel.getContentList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// ContentCurationViewModel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/09/27.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class ContentCurationViewModel: ObservableObject {
|
||||
|
||||
enum Sort: String {
|
||||
case NEWEST, PRICE_HIGH, PRICE_LOW
|
||||
}
|
||||
|
||||
private let repository = ContentRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var totalCount = 0
|
||||
@Published var sort = Sort.NEWEST {
|
||||
didSet {
|
||||
page = 1
|
||||
isLast = false
|
||||
getContentList()
|
||||
}
|
||||
}
|
||||
|
||||
@Published var contentList: [GetAudioContentMainItem] = []
|
||||
|
||||
var curationId = 0
|
||||
var page = 1
|
||||
var isLast = false
|
||||
private let pageSize = 10
|
||||
|
||||
func getContentList() {
|
||||
if (!isLast && !isLoading) {
|
||||
isLoading = true
|
||||
|
||||
repository.getAudioContentListByCurationId(
|
||||
curationId: curationId,
|
||||
page: page,
|
||||
size: pageSize,
|
||||
sort: sort
|
||||
)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<GetCurationContentResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
if page == 1 {
|
||||
self.contentList.removeAll()
|
||||
}
|
||||
|
||||
if !data.items.isEmpty {
|
||||
page += 1
|
||||
self.totalCount = data.totalCount
|
||||
self.contentList.append(contentsOf: data.items)
|
||||
} else {
|
||||
isLast = true
|
||||
}
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// GetCurationContentResponse.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/09/27.
|
||||
//
|
||||
|
||||
struct GetCurationContentResponse: Decodable {
|
||||
let totalCount: Int
|
||||
let items: [GetAudioContentMainItem]
|
||||
}
|
Reference in New Issue
Block a user