feat(series-all-home): 시리즈 전체보기 홈 탭 - 추천 시리즈 UI 추가
This commit is contained in:
@@ -12,45 +12,98 @@ struct SeriesMainHomeView: View {
|
|||||||
@StateObject var viewModel = SeriesMainHomeViewModel()
|
@StateObject var viewModel = SeriesMainHomeViewModel()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
ZStack {
|
||||||
VStack(spacing: 48) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
SeriesMainHomeBannerView(bannerList: viewModel.banners)
|
VStack(spacing: 48) {
|
||||||
.padding(.top, 24)
|
if !viewModel.banners.isEmpty {
|
||||||
|
SeriesMainHomeBannerView(bannerList: viewModel.banners)
|
||||||
if !viewModel.completedSeriesList.isEmpty {
|
.padding(.top, 24)
|
||||||
VStack(alignment: .leading, spacing: 16) {
|
}
|
||||||
HStack(spacing: 0) {
|
|
||||||
Text("완결 시리즈")
|
if !viewModel.completedSeriesList.isEmpty {
|
||||||
.font(.custom(Font.preBold.rawValue, size: 24))
|
VStack(alignment: .leading, spacing: 16) {
|
||||||
.foregroundColor(.white)
|
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()
|
ScrollView(.horizontal, showsIndicators: false) {
|
||||||
|
LazyHStack(spacing: 16) {
|
||||||
Text("전체보기")
|
ForEach(0..<viewModel.completedSeriesList.count, id: \.self) {
|
||||||
.font(.custom(Font.preRegular.rawValue, size: 14))
|
let item = viewModel.completedSeriesList[$0]
|
||||||
.foregroundColor(.init(hex: "78909C"))
|
NavigationLink {
|
||||||
|
SeriesDetailView(seriesId: item.seriesId)
|
||||||
|
} label: {
|
||||||
|
SeriesMainItemView(item: item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 24)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 24)
|
}
|
||||||
|
|
||||||
ScrollView(.horizontal, showsIndicators: false) {
|
if !viewModel.recommendSeriesList.isEmpty {
|
||||||
LazyHStack(spacing: 16) {
|
VStack(alignment: .leading, spacing: 16) {
|
||||||
ForEach(0..<viewModel.completedSeriesList.count, id: \.self) {
|
HStack(spacing: 0) {
|
||||||
let item = viewModel.completedSeriesList[$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 {
|
NavigationLink {
|
||||||
SeriesDetailView(seriesId: item.seriesId)
|
SeriesDetailView(seriesId: item.seriesId)
|
||||||
} label: {
|
} label: {
|
||||||
SeriesMainItemView(item: item)
|
SeriesMainItemView(item: item, width: width, height: width * 227 / 160)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 24)
|
.padding(.horizontal, horizontalPadding)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
.onAppear {
|
||||||
.onAppear {
|
viewModel.fetchHome()
|
||||||
viewModel.fetchHome()
|
}
|
||||||
|
|
||||||
|
if viewModel.isLoading {
|
||||||
|
LoadingView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ final class SeriesMainHomeViewModel: ObservableObject {
|
|||||||
|
|
||||||
@Published var banners: [SeriesBannerResponse] = []
|
@Published var banners: [SeriesBannerResponse] = []
|
||||||
@Published var completedSeriesList: [SeriesListItem] = []
|
@Published var completedSeriesList: [SeriesListItem] = []
|
||||||
|
@Published var recommendSeriesList: [SeriesListItem] = []
|
||||||
|
|
||||||
func fetchHome() {
|
func fetchHome() {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
repository
|
repository.fetchHome()
|
||||||
.fetchHome()
|
|
||||||
.sink { result in
|
.sink { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .finished:
|
case .finished:
|
||||||
@@ -40,6 +40,45 @@ final class SeriesMainHomeViewModel: ObservableObject {
|
|||||||
if let data = decoded.data, decoded.success {
|
if let data = decoded.data, decoded.success {
|
||||||
self.banners = data.banners
|
self.banners = data.banners
|
||||||
self.completedSeriesList = data.completedSeriesList
|
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 {
|
} else {
|
||||||
if let message = decoded.message {
|
if let message = decoded.message {
|
||||||
self.errorMessage = message
|
self.errorMessage = message
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import Moya
|
|||||||
|
|
||||||
enum SeriesMainApi {
|
enum SeriesMainApi {
|
||||||
case fetchHome(isAdultContentVisible: Bool, contentType: ContentType)
|
case fetchHome(isAdultContentVisible: Bool, contentType: ContentType)
|
||||||
|
case getRecommendSeriesList(isAdultContentVisible: Bool, contentType: ContentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SeriesMainApi: TargetType {
|
extension SeriesMainApi: TargetType {
|
||||||
@@ -18,6 +19,9 @@ extension SeriesMainApi: TargetType {
|
|||||||
switch self {
|
switch self {
|
||||||
case .fetchHome:
|
case .fetchHome:
|
||||||
return "/audio-content/series/main"
|
return "/audio-content/series/main"
|
||||||
|
|
||||||
|
case .getRecommendSeriesList:
|
||||||
|
return "/audio-content/series/main/recommend"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +33,14 @@ extension SeriesMainApi: TargetType {
|
|||||||
"contentType": contentType,
|
"contentType": contentType,
|
||||||
] as [String : Any]
|
] 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)
|
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