feat(series-all-home): 시리즈 전체보기 홈 탭 - 추천 시리즈 UI 추가
This commit is contained in:
@@ -12,45 +12,98 @@ struct SeriesMainHomeView: View {
|
||||
@StateObject var viewModel = SeriesMainHomeViewModel()
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack(spacing: 48) {
|
||||
SeriesMainHomeBannerView(bannerList: viewModel.banners)
|
||||
.padding(.top, 24)
|
||||
|
||||
if !viewModel.completedSeriesList.isEmpty {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
HStack(spacing: 0) {
|
||||
Text("완결 시리즈")
|
||||
.font(.custom(Font.preBold.rawValue, size: 24))
|
||||
.foregroundColor(.white)
|
||||
ZStack {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack(spacing: 48) {
|
||||
if !viewModel.banners.isEmpty {
|
||||
SeriesMainHomeBannerView(bannerList: viewModel.banners)
|
||||
.padding(.top, 24)
|
||||
}
|
||||
|
||||
if !viewModel.completedSeriesList.isEmpty {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
HStack(spacing: 0) {
|
||||
Text("완결 시리즈")
|
||||
.font(.custom(Font.preBold.rawValue, size: 24))
|
||||
.foregroundColor(.white)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("전체보기")
|
||||
.font(.custom(Font.preRegular.rawValue, size: 14))
|
||||
.foregroundColor(.init(hex: "78909C"))
|
||||
}
|
||||
.padding(.horizontal, 24)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("전체보기")
|
||||
.font(.custom(Font.preRegular.rawValue, size: 14))
|
||||
.foregroundColor(.init(hex: "78909C"))
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
LazyHStack(spacing: 16) {
|
||||
ForEach(0..<viewModel.completedSeriesList.count, id: \.self) {
|
||||
let item = viewModel.completedSeriesList[$0]
|
||||
NavigationLink {
|
||||
SeriesDetailView(seriesId: item.seriesId)
|
||||
} label: {
|
||||
SeriesMainItemView(item: item)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 24)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 24)
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
LazyHStack(spacing: 16) {
|
||||
ForEach(0..<viewModel.completedSeriesList.count, id: \.self) {
|
||||
let item = viewModel.completedSeriesList[$0]
|
||||
}
|
||||
|
||||
if !viewModel.recommendSeriesList.isEmpty {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
HStack(spacing: 0) {
|
||||
Text("추천 시리즈")
|
||||
.font(.custom(Font.preBold.rawValue, size: 24))
|
||||
.foregroundColor(.white)
|
||||
|
||||
Spacer()
|
||||
|
||||
Image("ic_refresh")
|
||||
.onTapGesture {
|
||||
viewModel.getRecommendSeriesList()
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 24)
|
||||
|
||||
let horizontalPadding: CGFloat = 24
|
||||
let gridSpacing: CGFloat = 16
|
||||
let width = (screenSize().width - (horizontalPadding * 2) - gridSpacing) / 2
|
||||
|
||||
LazyVGrid(
|
||||
columns: Array(
|
||||
repeating: GridItem(
|
||||
.flexible(),
|
||||
spacing: gridSpacing,
|
||||
alignment: .topLeading
|
||||
),
|
||||
count: 2
|
||||
),
|
||||
alignment: .leading,
|
||||
spacing: gridSpacing
|
||||
) {
|
||||
ForEach(viewModel.recommendSeriesList.indices, id: \.self) {
|
||||
let item = viewModel.recommendSeriesList[$0]
|
||||
NavigationLink {
|
||||
SeriesDetailView(seriesId: item.seriesId)
|
||||
} label: {
|
||||
SeriesMainItemView(item: item)
|
||||
SeriesMainItemView(item: item, width: width, height: width * 227 / 160)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 24)
|
||||
.padding(.horizontal, horizontalPadding)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.fetchHome()
|
||||
.onAppear {
|
||||
viewModel.fetchHome()
|
||||
}
|
||||
|
||||
if viewModel.isLoading {
|
||||
LoadingView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ final class SeriesMainHomeViewModel: ObservableObject {
|
||||
|
||||
@Published var banners: [SeriesBannerResponse] = []
|
||||
@Published var completedSeriesList: [SeriesListItem] = []
|
||||
@Published var recommendSeriesList: [SeriesListItem] = []
|
||||
|
||||
func fetchHome() {
|
||||
isLoading = true
|
||||
repository
|
||||
.fetchHome()
|
||||
repository.fetchHome()
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
@@ -40,6 +40,45 @@ final class SeriesMainHomeViewModel: ObservableObject {
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.banners = data.banners
|
||||
self.completedSeriesList = data.completedSeriesList
|
||||
self.recommendSeriesList = data.recommendSeriesList
|
||||
} 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 getRecommendSeriesList() {
|
||||
isLoading = true
|
||||
repository.getRecommendSeriesList()
|
||||
.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<[SeriesListItem]>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.recommendSeriesList = data
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
|
||||
@@ -10,6 +10,7 @@ import Moya
|
||||
|
||||
enum SeriesMainApi {
|
||||
case fetchHome(isAdultContentVisible: Bool, contentType: ContentType)
|
||||
case getRecommendSeriesList(isAdultContentVisible: Bool, contentType: ContentType)
|
||||
}
|
||||
|
||||
extension SeriesMainApi: TargetType {
|
||||
@@ -18,6 +19,9 @@ extension SeriesMainApi: TargetType {
|
||||
switch self {
|
||||
case .fetchHome:
|
||||
return "/audio-content/series/main"
|
||||
|
||||
case .getRecommendSeriesList:
|
||||
return "/audio-content/series/main/recommend"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +33,14 @@ extension SeriesMainApi: TargetType {
|
||||
"contentType": contentType,
|
||||
] as [String : Any]
|
||||
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
|
||||
|
||||
case .getRecommendSeriesList(let isAdultContentVisible, let contentType):
|
||||
let parameters = [
|
||||
"isAdultContentVisible": isAdultContentVisible,
|
||||
"contentType": contentType,
|
||||
] as [String : Any]
|
||||
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,13 @@ class SeriesMainRepository {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
func getRecommendSeriesList() -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(
|
||||
.getRecommendSeriesList(
|
||||
isAdultContentVisible: UserDefaults.isAdultContentVisible(),
|
||||
contentType: ContentType(rawValue: UserDefaults.string(forKey: .contentPreference)) ?? ContentType.ALL
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user