콘텐츠 메인 시리즈 탭
- 완결 시리즈 전체보기 추가
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// CompletedSeriesView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2/22/25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CompletedSeriesView: View {
|
||||
|
||||
@StateObject var viewModel = CompletedSeriesViewModel()
|
||||
|
||||
private let columns = [
|
||||
GridItem(.flexible()),
|
||||
GridItem(.flexible()),
|
||||
GridItem(.flexible())
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
VStack(spacing: 13.3) {
|
||||
DetailNavigationBar(title: "완결 시리즈")
|
||||
|
||||
HStack(alignment: .center, spacing: 0) {
|
||||
Text("전체")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(.graye2)
|
||||
|
||||
Text("\(viewModel.totalCount)")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(.mainRed)
|
||||
.padding(.leading, 6.7)
|
||||
|
||||
Text("개")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(.graye2)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
LazyVGrid(columns: columns, spacing: 13.3) {
|
||||
ForEach(0..<viewModel.rankCompleteSeriesList.count, id: \.self) { index in
|
||||
let item = viewModel.rankCompleteSeriesList[index]
|
||||
|
||||
SeriesListItemView(
|
||||
itemWidth: (screenSize().width - (13.3 * 4)) / 3,
|
||||
item: item
|
||||
)
|
||||
.onAppear {
|
||||
if index == viewModel.rankCompleteSeriesList.count - 1 {
|
||||
viewModel.getCompletedSeries()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 13.3)
|
||||
}
|
||||
}
|
||||
}
|
||||
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .bottom, autohideIn: 2) {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(viewModel.errorMessage)
|
||||
.padding(.vertical, 13.3)
|
||||
.frame(width: screenSize().width - 66.7, alignment: .center)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.background(Color.button)
|
||||
.foregroundColor(Color.white)
|
||||
.multilineTextAlignment(.leading)
|
||||
.cornerRadius(20)
|
||||
.padding(.bottom, 66.7)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.getCompletedSeries()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
CompletedSeriesView()
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// CompletedSeriesViewModel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2/22/25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class CompletedSeriesViewModel: ObservableObject {
|
||||
private let repository = ContentMainTabSeriesRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var rankCompleteSeriesList: [SeriesListItem] = []
|
||||
@Published var totalCount = 0
|
||||
|
||||
var isLast = false
|
||||
var page = 1
|
||||
private let size = 20
|
||||
|
||||
func getCompletedSeries() {
|
||||
if !isLast && !isLoading {
|
||||
isLoading = true
|
||||
|
||||
repository.getCompletedSeries(page: page, size: size)
|
||||
.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<GetSeriesListResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
page += 1
|
||||
|
||||
if (data.items.count > 0) {
|
||||
self.totalCount = data.totalCount
|
||||
self.rankCompleteSeriesList = 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user