콘텐츠 메인

- ASMR 탭 UI 페이지 생성
This commit is contained in:
Yu Sung
2025-02-22 05:05:07 +09:00
parent 53266dc91b
commit 021fbd5294
6 changed files with 188 additions and 12 deletions

View File

@@ -0,0 +1,24 @@
//
// ContentMainTabAsmrRepository.swift
// SodaLive
//
// Created by klaus on 2/22/25.
//
import Foundation
import CombineMoya
import Combine
import Moya
final class ContentMainTabAsmrRepository {
private let api = MoyaProvider<ContentApi>()
func getContentMainAsmr() -> AnyPublisher<Response, MoyaError> {
return api.requestPublisher(.getContentMainAsmr)
}
func getPopularContentByCreator(creatorId: Int) -> AnyPublisher<Response, MoyaError> {
return api.requestPublisher(.getPopularContentByCreator(creatorId: creatorId))
}
}

View File

@@ -8,8 +8,70 @@
import SwiftUI
struct ContentMainTabAsmrView: View {
@StateObject var viewModel = ContentMainTabAsmrViewModel()
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
BaseView(isLoading: $viewModel.isLoading) {
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 0) {
if !viewModel.bannerList.isEmpty {
ContentMainBannerViewV2(bannerList: viewModel.bannerList)
.padding(.horizontal, 13.3)
}
if !viewModel.newAsmrContentList.isEmpty {
ContentMainNewContentViewV2(
title: "새로운 ASMR",
onClickMore: {},
themeList: [],
contentList: viewModel.newAsmrContentList
) { _ in }
.padding(.top, 30)
}
if !viewModel.creatorList.isEmpty {
ContentByChannelView(
title: "채널별 추천 ASMR",
creatorList: viewModel.creatorList,
contentList: viewModel.salesCountRankContentList,
onClickCreator: {
viewModel.getPopularContentByCreator(creatorId: $0)
}
)
.padding(.top, 30)
}
if !viewModel.eventBannerList.isEmpty {
SectionEventBannerView(items: viewModel.eventBannerList)
.padding(.top, 30)
}
if !viewModel.curationList.isEmpty {
ContentMainCurationViewV2(curationList: viewModel.curationList)
.padding(.top, 30)
}
}
.onAppear {
viewModel.fetchData()
}
}
}
.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()
}
}
}
}

View File

@@ -6,9 +6,67 @@
//
import Foundation
import Combine
final class ContentMainTabAsmrViewModel: ObservableObject {
private let repository = ContentMainTabAsmrRepository()
private var subscription = Set<AnyCancellable>()
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var isLoading = false
@Published var bannerList: [GetAudioContentBannerResponse] = []
@Published var newAsmrContentList: [GetAudioContentMainItem] = []
@Published var creatorList: [ContentCreatorResponse] = []
@Published var salesCountRankContentList: [GetAudioContentRankingItem] = []
@Published var eventBannerList: [EventItem] = []
@Published var curationList: [GetContentCurationResponse] = []
func fetchData() {
isLoading = true
repository.getContentMainAsmr()
.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<GetContentMainTabAsmrResponse>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.bannerList = data.contentBannerList
self.newAsmrContentList = data.newAsmrContentList
self.creatorList = data.creatorList
self.salesCountRankContentList = data.salesCountRankContentList
self.eventBannerList = data.eventBannerList.eventList
self.curationList = data.curationList
} 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 getPopularContentByCreator(creatorId: Int) {
}
}

View File

@@ -0,0 +1,15 @@
//
// GetContentMainTabAsmrResponse.swift
// SodaLive
//
// Created by klaus on 2/22/25.
//
struct GetContentMainTabAsmrResponse: Decodable {
let contentBannerList: [GetAudioContentBannerResponse]
let newAsmrContentList: [GetAudioContentMainItem]
let creatorList: [ContentCreatorResponse]
let salesCountRankContentList: [GetAudioContentRankingItem]
let eventBannerList: GetEventResponse
let curationList: [GetContentCurationResponse]
}