콘텐츠 메인

- 추천 시리즈 UI 추가
This commit is contained in:
Yu Sung
2024-05-07 17:49:36 +09:00
parent 83d51a525b
commit bcba83a8a7
9 changed files with 100 additions and 125 deletions

View File

@@ -6,7 +6,6 @@
//
import SwiftUI
import RefreshableScrollView
struct ContentMainView: View {
@@ -16,12 +15,7 @@ struct ContentMainView: View {
ZStack(alignment: .bottomTrailing) {
Color.black.ignoresSafeArea()
RefreshableScrollView(
refreshing: $viewModel.isLoading,
action: {
viewModel.refresh()
}
) {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading, spacing: 0) {
Text("콘텐츠 마켓")
.font(.custom(Font.bold.rawValue, size: 21.3))
@@ -30,9 +24,7 @@ struct ContentMainView: View {
.padding(.horizontal, 13.3)
if !viewModel.isLoading {
ContentMainNewContentCreatorView()
.padding(.bottom, 26.7)
.padding(.horizontal, 13.3)
ContentMainRecommendSeriesView()
ContentMainBannerView()
.padding(.bottom, 26.7)
@@ -124,10 +116,10 @@ struct ContentMainView: View {
AppState.shared.setAppStep(step: .createContent)
}
}
if viewModel.isLoading {
LoadingView()
}
}
if viewModel.isLoading {
LoadingView()
}
}
}

View File

@@ -1,45 +0,0 @@
//
// ContentMainNewContentCreatorItemView.swift
// SodaLive
//
// Created by klaus on 2023/08/11.
//
import SwiftUI
import Kingfisher
struct ContentMainNewContentCreatorItemView: View {
let item: GetNewContentUploadCreator
var body: some View {
VStack(spacing: 8) {
KFImage(URL(string: item.creatorProfileImageUrl))
.resizable()
.scaledToFill()
.frame(width: screenSize().width * 0.18, height: screenSize().width * 0.18, alignment: .top)
.clipShape(Circle())
Text(item.creatorNickname)
.font(.custom(Font.medium.rawValue, size: 11.3))
.foregroundColor(Color(hex: "bbbbbb"))
.frame(width: screenSize().width * 0.18)
.lineLimit(1)
}
.onTapGesture {
AppState.shared.setAppStep(step: .creatorDetail(userId: item.creatorId))
}
}
}
struct ContentMainNewContentCreatorItemView_Previews: PreviewProvider {
static var previews: some View {
ContentMainNewContentCreatorItemView(
item: GetNewContentUploadCreator(
creatorId: 2,
creatorNickname: "수다친구112",
creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png"
)
)
}
}

View File

@@ -1,43 +0,0 @@
//
// ContentMainNewContentCreatorView.swift
// SodaLive
//
// Created by klaus on 2023/08/11.
//
import SwiftUI
struct ContentMainNewContentCreatorView: View {
@StateObject private var viewModel = ContentMainNewContentCreatorViewModel()
var body: some View {
ZStack {
if !viewModel.newContentUploadCreatorList.isEmpty {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 21.3) {
ForEach(0..<viewModel.newContentUploadCreatorList.count, id: \.self) { index in
let item = viewModel.newContentUploadCreatorList[index]
ContentMainNewContentCreatorItemView(item: item)
}
}
}
}
if viewModel.isLoading {
ActivityIndicatorView()
.frame(width: 100, height: 100)
}
}
.frame(maxWidth: .infinity)
.onAppear {
viewModel.getNewContentUploadCreatorList()
}
}
}
struct ContentMainNewContentCreatorView_Previews: PreviewProvider {
static var previews: some View {
ContentMainNewContentCreatorView()
}
}

View File

@@ -0,0 +1,45 @@
//
// ContentMainRecommendSeriesView.swift
// SodaLive
//
// Created by klaus on 5/7/24.
//
import SwiftUI
struct ContentMainRecommendSeriesView: View {
@StateObject private var viewModel = ContentMainRecommendSeriesViewModel()
var body: some View {
ZStack {
if !viewModel.seriesList.isEmpty {
VStack(alignment: .leading, spacing: 13.3) {
Text("추천 시리즈")
.font(.custom(Font.bold.rawValue, size: 18.3))
.foregroundColor(Color.grayee)
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: 13.3) {
ForEach(0..<viewModel.seriesList.count, id: \.self) {
let item = viewModel.seriesList[$0]
SeriesListBigItemView(item: item, isVisibleCreator: true)
}
}
}
}
.padding(.bottom, 26.7)
.padding(.horizontal, 13.3)
} else {
EmptyView()
}
}
.onAppear {
viewModel.getRecommendSeriesList()
}
}
}
#Preview {
ContentMainRecommendSeriesView()
}

View File

@@ -1,28 +1,26 @@
//
// ContentMainNewContentCreatorViewModel.swift
// ContentMainRecommendSeriesViewModel.swift
// SodaLive
//
// Created by klaus on 2023/12/11.
// Created by klaus on 5/7/24.
//
import Foundation
import Combine
final class ContentMainNewContentCreatorViewModel: ObservableObject {
final class ContentMainRecommendSeriesViewModel: ObservableObject {
private let repository = ContentRepository()
private let repository = SeriesRepository()
private var subscription = Set<AnyCancellable>()
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var isLoading = false
@Published var newContentUploadCreatorList = [GetNewContentUploadCreator]()
@Published var seriesList = [SeriesListItem]()
func getNewContentUploadCreatorList() {
isLoading = true
repository.getNewContentUploadCreatorList()
func getRecommendSeriesList() {
repository.getRecommendSeriesList()
.sink { result in
switch result {
case .finished:
@@ -36,23 +34,23 @@ final class ContentMainNewContentCreatorViewModel: ObservableObject {
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<[GetNewContentUploadCreator]>.self, from: responseData)
let decoded = try jsonDecoder.decode(ApiResponse<[SeriesListItem]>.self, from: responseData)
self.isLoading = false
if let data = decoded.data, decoded.success {
self.newContentUploadCreatorList.removeAll()
self.newContentUploadCreatorList.append(contentsOf: data)
self.seriesList.removeAll()
self.seriesList.append(contentsOf: data)
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "크리에이터 리스트를 불러오지 못했습니다. 다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.errorMessage = "추천 시리즈를 불러오지 못했습니다. 다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "크리에이터 리스트를 불러오지 못했습니다. 다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.errorMessage = "추천 시리즈를 불러오지 못했습니다. 다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
self.isLoading = false
}