콘텐츠 메인, 콘텐츠 업로드 페이지 추가
This commit is contained in:
114
SodaLive/Sources/Content/Main/ContentMainBannerView.swift
Normal file
114
SodaLive/Sources/Content/Main/ContentMainBannerView.swift
Normal file
@@ -0,0 +1,114 @@
|
||||
//
|
||||
// ContentMainBannerView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Kingfisher
|
||||
|
||||
struct ContentMainBannerView: View {
|
||||
|
||||
let items: [GetAudioContentBannerResponse]
|
||||
@State private var currentIndex = 0
|
||||
@State private var timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
TabView(selection: $currentIndex) {
|
||||
ForEach(0..<items.count, id: \.self) { index in
|
||||
let item = items[index]
|
||||
if let url = item.thumbnailImageUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
|
||||
KFImage(URL(string: url))
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(
|
||||
width: screenSize().width - 26.7,
|
||||
height: (screenSize().width - 26.7) * 0.53
|
||||
)
|
||||
.onTapGesture {
|
||||
switch item.type {
|
||||
case .EVENT:
|
||||
AppState.shared.setAppStep(step: .eventDetail(event: item.eventItem!))
|
||||
case .CREATOR:
|
||||
break
|
||||
case .LINK:
|
||||
if let link = item.link, link.trimmingCharacters(in: .whitespaces).count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
.cornerRadius(4.7)
|
||||
} else {
|
||||
KFImage(URL(string: item.thumbnailImageUrl))
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(
|
||||
width: screenSize().width - 26.7,
|
||||
height: (screenSize().width - 26.7) * 0.53
|
||||
)
|
||||
.onTapGesture {
|
||||
switch item.type {
|
||||
case .EVENT:
|
||||
AppState.shared.setAppStep(step: .eventDetail(event: item.eventItem!))
|
||||
case .CREATOR:
|
||||
break
|
||||
case .LINK:
|
||||
if let link = item.link, link.trimmingCharacters(in: .whitespaces).count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
.cornerRadius(4.7)
|
||||
}
|
||||
}
|
||||
}
|
||||
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
|
||||
.frame(
|
||||
width: screenSize().width - 26.7,
|
||||
height: (screenSize().width - 26.7) * 0.53
|
||||
)
|
||||
|
||||
HStack(spacing: 4) {
|
||||
ForEach(0..<items.count, id: \.self) { index in
|
||||
Capsule()
|
||||
.foregroundColor(index == currentIndex ? Color(hex: "9970ff") : Color(hex: "909090"))
|
||||
.frame(
|
||||
width: index == currentIndex ? 18 : 6,
|
||||
height: 6
|
||||
)
|
||||
.tag(index)
|
||||
}
|
||||
}
|
||||
.padding(.top, 13.3)
|
||||
}
|
||||
.frame(width: screenSize().width - 26.7)
|
||||
.onAppear {
|
||||
timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
|
||||
}
|
||||
.onDisappear {
|
||||
timer.upstream.connect().cancel()
|
||||
}
|
||||
.onReceive(timer) { _ in
|
||||
DispatchQueue.main.async {
|
||||
withAnimation {
|
||||
if currentIndex == items.count - 1 {
|
||||
currentIndex = 0
|
||||
} else {
|
||||
currentIndex += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentMainBannerView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentMainBannerView(
|
||||
items: [
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// ContentMainCurationItemView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentMainCurationItemView: View {
|
||||
|
||||
let item: GetAudioContentCurationResponse
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text(item.title)
|
||||
.font(.custom(Font.bold.rawValue, size: 18.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text(item.description)
|
||||
.font(.custom(Font.medium.rawValue, size: 13))
|
||||
.foregroundColor(Color(hex: "777777"))
|
||||
.padding(.top, 4)
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
LazyHStack(alignment: .top, spacing: 13.3) {
|
||||
ForEach(0..<item.audioContents.count, id: \.self) {
|
||||
let audioContent = item.audioContents[$0]
|
||||
ContentMainItemView(item: audioContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.top, 13.3)
|
||||
}
|
||||
}
|
||||
}
|
22
SodaLive/Sources/Content/Main/ContentMainCurationView.swift
Normal file
22
SodaLive/Sources/Content/Main/ContentMainCurationView.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// ContentMainCurationView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentMainCurationView: View {
|
||||
|
||||
let items: [GetAudioContentCurationResponse]
|
||||
|
||||
var body: some View {
|
||||
LazyVStack(spacing: 40) {
|
||||
ForEach(0..<items.count, id: \.self) {
|
||||
let item = items[$0]
|
||||
ContentMainCurationItemView(item: item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
78
SodaLive/Sources/Content/Main/ContentMainItemView.swift
Normal file
78
SodaLive/Sources/Content/Main/ContentMainItemView.swift
Normal file
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// ContentMainItemView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Kingfisher
|
||||
|
||||
struct ContentMainItemView: View {
|
||||
|
||||
let item: GetAudioContentMainItem
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
ZStack(alignment: .topLeading) {
|
||||
KFImage(URL(string: item.coverImageUrl))
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(width: 133.3, height: 133.3, alignment: .top)
|
||||
.cornerRadius(2.7)
|
||||
|
||||
if item.isAdult {
|
||||
Text("19")
|
||||
.font(.custom(Font.bold.rawValue, size: 11.3))
|
||||
.foregroundColor(Color.white)
|
||||
.padding(4)
|
||||
.background(Color(hex: "e53621"))
|
||||
.clipShape(Circle())
|
||||
.padding(.top, 4.3)
|
||||
.padding(.leading, 4.3)
|
||||
}
|
||||
}
|
||||
|
||||
Text(item.title)
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "d2d2d2"))
|
||||
.frame(width: 133.3, alignment: .leading)
|
||||
.multilineTextAlignment(.leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.lineLimit(2)
|
||||
|
||||
HStack(spacing: 5.3) {
|
||||
KFImage(URL(string: item.creatorProfileImageUrl))
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(width: 21.3, height: 21.3)
|
||||
.clipShape(Circle())
|
||||
.onTapGesture { }
|
||||
|
||||
Text(item.creatorNickname)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "777777"))
|
||||
.lineLimit(1)
|
||||
}
|
||||
.padding(.bottom, 10)
|
||||
}
|
||||
.frame(width: 133.3, alignment: .leading)
|
||||
.onTapGesture { }
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentMainItemView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentMainItemView(
|
||||
item: GetAudioContentMainItem(
|
||||
contentId: 2,
|
||||
coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
|
||||
title: "ㅓ처랴햐햫햐햐",
|
||||
isAdult: true,
|
||||
creatorId: 8,
|
||||
creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
|
||||
creatorNickname: "유저2"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
57
SodaLive/Sources/Content/Main/ContentMainMyStashView.swift
Normal file
57
SodaLive/Sources/Content/Main/ContentMainMyStashView.swift
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// ContentMainMyStashView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentMainMyStashView: View {
|
||||
|
||||
let items: [GetAudioContentMainItem]
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 13.3) {
|
||||
HStack(spacing: 0) {
|
||||
Text("내 보관함")
|
||||
.font(.custom(Font.bold.rawValue, size: 18.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("전체보기")
|
||||
.font(.custom(Font.light.rawValue, size: 11.3))
|
||||
.foregroundColor(Color(hex: "bbbbbb"))
|
||||
.onTapGesture {}
|
||||
}
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
LazyHStack(alignment: .top, spacing: 13.3) {
|
||||
ForEach(0..<items.count, id: \.self) { index in
|
||||
let item = items[index]
|
||||
ContentMainItemView(item: item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentMainMyStashView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentMainMyStashView(
|
||||
items: [
|
||||
GetAudioContentMainItem(
|
||||
contentId: 1,
|
||||
coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
|
||||
title: "테스트",
|
||||
isAdult: false,
|
||||
creatorId: 7,
|
||||
creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
|
||||
creatorNickname: "유저1"
|
||||
)
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// 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 {}
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// ContentMainNewContentCreatorView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentMainNewContentCreatorView: View {
|
||||
|
||||
let items: [GetNewContentUploadCreator]
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
LazyHStack(spacing: 21.3) {
|
||||
ForEach(0..<items.count, id: \.self) { index in
|
||||
let item = items[index]
|
||||
ContentMainNewContentCreatorItemView(item: item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentMainNewContentCreatorView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentMainNewContentCreatorView(
|
||||
items: [
|
||||
GetNewContentUploadCreator(
|
||||
creatorId: 1,
|
||||
creatorNickname: "수다친구1",
|
||||
creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png"
|
||||
),
|
||||
GetNewContentUploadCreator(
|
||||
creatorId: 2,
|
||||
creatorNickname: "수다친구2",
|
||||
creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png"
|
||||
),
|
||||
GetNewContentUploadCreator(
|
||||
creatorId: 3,
|
||||
creatorNickname: "수다친구3",
|
||||
creatorProfileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png"
|
||||
)
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// ContentMainNewContentThemeView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentMainNewContentThemeView: View {
|
||||
let themes: [String]
|
||||
let selectTheme: (String) -> Void
|
||||
|
||||
@Binding var selectedTheme: String
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
ForEach(0..<themes.count, id: \.self) { index in
|
||||
let theme = themes[index]
|
||||
Text(theme)
|
||||
.font(.custom(Font.medium.rawValue, size: 14.7))
|
||||
.foregroundColor(Color(hex: selectedTheme == theme ? "9970ff" : "777777"))
|
||||
.padding(.horizontal, 13.3)
|
||||
.padding(.vertical, 9.3)
|
||||
.border(
|
||||
Color(hex: selectedTheme == theme ? "9970ff" : "eeeeee"),
|
||||
width: 0.5
|
||||
)
|
||||
.cornerRadius(16.7)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: CGFloat(16.7))
|
||||
.stroke(lineWidth: 0.5)
|
||||
.foregroundColor(Color(hex: selectedTheme == theme ? "9970ff" : "eeeeee"))
|
||||
)
|
||||
.onTapGesture { selectTheme(theme) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentMainNewContentThemeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentMainNewContentThemeView(
|
||||
themes: ["전체", "테마1", "테마2"],
|
||||
selectTheme: { _ in },
|
||||
selectedTheme: .constant("전체")
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// ContentMainNewContentView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentMainNewContentView: View {
|
||||
|
||||
let themes: [String]
|
||||
let items: [GetAudioContentMainItem]
|
||||
|
||||
let selectTheme: (String) -> Void
|
||||
@Binding var selectedTheme: String
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text("새로운 콘텐츠")
|
||||
.font(.custom(Font.bold.rawValue, size: 18.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
ContentMainNewContentThemeView(themes: themes, selectTheme: selectTheme, selectedTheme: $selectedTheme)
|
||||
.padding(.vertical, 16.7)
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .top, spacing: 13.3) {
|
||||
ForEach(0..<items.count, id: \.self) {
|
||||
ContentMainItemView(item: items[$0])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentMainNewContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentMainNewContentView(
|
||||
themes: ["전체", "테마1", "테마2"],
|
||||
items: [
|
||||
GetAudioContentMainItem(
|
||||
contentId: 1,
|
||||
coverImageUrl: "https://test-cf.yozm.day/audio_content_cover/31/31-cover-e78575f9-7624-471c-8102-1289a5748aae-5983-1684487894269",
|
||||
title: "테스트",
|
||||
isAdult: false,
|
||||
creatorId: 7,
|
||||
creatorProfileImageUrl: "https://test-cf.yozm.day/profile/7f73168e-220f-482f-b97d-baab63b70e04IMG_20220314_220855522.jpg",
|
||||
creatorNickname: "유저1"
|
||||
)
|
||||
],
|
||||
selectTheme: { _ in },
|
||||
selectedTheme: .constant("전체")
|
||||
)
|
||||
}
|
||||
}
|
@@ -6,10 +6,105 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import RefreshableScrollView
|
||||
|
||||
struct ContentMainView: View {
|
||||
|
||||
@StateObject var viewModel = ContentMainViewModel()
|
||||
|
||||
var body: some View {
|
||||
Text("Content")
|
||||
ZStack(alignment: .bottomTrailing) {
|
||||
Color.black.ignoresSafeArea()
|
||||
|
||||
RefreshableScrollView(
|
||||
refreshing: $viewModel.isLoading,
|
||||
action: {
|
||||
viewModel.getMain()
|
||||
}
|
||||
) {
|
||||
LazyVStack(alignment: .leading, spacing: 0) {
|
||||
Text("콘텐츠 마켓")
|
||||
.font(.custom(Font.bold.rawValue, size: 21.3))
|
||||
.foregroundColor(Color(hex: "9970ff"))
|
||||
.padding(.bottom, 26.7)
|
||||
|
||||
if viewModel.newContentUploadCreatorList.count > 0 {
|
||||
ContentMainNewContentCreatorView(items: viewModel.newContentUploadCreatorList)
|
||||
.padding(.bottom, 26.7)
|
||||
}
|
||||
|
||||
if viewModel.bannerList.count > 0 {
|
||||
ContentMainBannerView(items: viewModel.bannerList)
|
||||
.padding(.bottom, 40)
|
||||
}
|
||||
|
||||
if viewModel.orderList.count > 0 {
|
||||
ContentMainMyStashView(items: viewModel.orderList)
|
||||
.padding(.bottom, 40)
|
||||
}
|
||||
|
||||
ContentMainNewContentView(
|
||||
themes: viewModel.themeList,
|
||||
items: viewModel.newContentList,
|
||||
selectTheme: { viewModel.selectedTheme = $0 },
|
||||
selectedTheme: $viewModel.selectedTheme
|
||||
)
|
||||
|
||||
if viewModel.curationList.count > 0 {
|
||||
ContentMainCurationView(items: viewModel.curationList)
|
||||
.padding(.top, 40)
|
||||
.padding(.bottom, 20)
|
||||
}
|
||||
}
|
||||
.padding(13.3)
|
||||
}
|
||||
|
||||
if UserDefaults.string(forKey: .role) == MemberRole.CREATOR.rawValue {
|
||||
HStack(spacing: 5) {
|
||||
Image("ic_thumb_play")
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
|
||||
Text("콘텐츠 업로드")
|
||||
.font(.custom(Font.bold.rawValue, size: 13.3))
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
.padding(13.3)
|
||||
.background(Color(hex: "9970ff"))
|
||||
.cornerRadius(44)
|
||||
.padding(.trailing, 16.7)
|
||||
.padding(.bottom, 16.7)
|
||||
.onTapGesture {
|
||||
AppState.shared.setAppStep(step: .createContent)
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.isLoading {
|
||||
LoadingView()
|
||||
}
|
||||
}
|
||||
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
|
||||
GeometryReader { geo in
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(viewModel.errorMessage)
|
||||
.padding(.vertical, 13.3)
|
||||
.padding(.horizontal, 6.7)
|
||||
.frame(width: geo.size.width - 66.7, alignment: .center)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.background(Color(hex: "9970ff"))
|
||||
.foregroundColor(Color.white)
|
||||
.multilineTextAlignment(.leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(20)
|
||||
.padding(.top, 66.7)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.getMain()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
124
SodaLive/Sources/Content/Main/ContentMainViewModel.swift
Normal file
124
SodaLive/Sources/Content/Main/ContentMainViewModel.swift
Normal file
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// ContentMainViewModel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
import Combine
|
||||
|
||||
final class ContentMainViewModel: ObservableObject {
|
||||
|
||||
private let repository = ContentRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var newContentUploadCreatorList = [GetNewContentUploadCreator]()
|
||||
@Published var newContentList = [GetAudioContentMainItem]()
|
||||
@Published var bannerList = [GetAudioContentBannerResponse]()
|
||||
@Published var orderList = [GetAudioContentMainItem]()
|
||||
@Published var themeList = [String]()
|
||||
@Published var curationList = [GetAudioContentCurationResponse]()
|
||||
|
||||
@Published var selectedTheme = "전체" {
|
||||
didSet {
|
||||
getNewContentOfTheme()
|
||||
}
|
||||
}
|
||||
|
||||
func getMain() {
|
||||
isLoading = true
|
||||
|
||||
repository.getMain()
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<GetAudioContentMainResponse>.self, from: responseData)
|
||||
self.isLoading = false
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.newContentUploadCreatorList.removeAll()
|
||||
self.newContentList.removeAll()
|
||||
self.bannerList.removeAll()
|
||||
self.orderList.removeAll()
|
||||
self.curationList.removeAll()
|
||||
self.themeList.removeAll()
|
||||
|
||||
self.newContentUploadCreatorList.append(contentsOf: data.newContentUploadCreatorList)
|
||||
self.newContentList.append(contentsOf: data.newContentList)
|
||||
self.bannerList.append(contentsOf: data.bannerList)
|
||||
self.orderList.append(contentsOf: data.orderList)
|
||||
self.curationList.append(contentsOf: data.curationList)
|
||||
|
||||
self.themeList.append("전체")
|
||||
self.themeList.append(contentsOf: data.themeList)
|
||||
} 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 getNewContentOfTheme() {
|
||||
repository.getNewContentOfTheme(theme: selectedTheme == "전체" ? "" : selectedTheme)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<[GetAudioContentMainItem]>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.newContentList.removeAll()
|
||||
self.newContentList.append(contentsOf: data)
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// GetAudioContentMainResponse.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GetAudioContentMainResponse: Decodable {
|
||||
let newContentUploadCreatorList: [GetNewContentUploadCreator]
|
||||
let bannerList: [GetAudioContentBannerResponse]
|
||||
let orderList: [GetAudioContentMainItem]
|
||||
let themeList: [String]
|
||||
let newContentList: [GetAudioContentMainItem]
|
||||
let curationList: [GetAudioContentCurationResponse]
|
||||
}
|
||||
|
||||
struct GetNewContentUploadCreator: Decodable {
|
||||
let creatorId: Int
|
||||
let creatorNickname: String
|
||||
let creatorProfileImageUrl: String
|
||||
}
|
||||
|
||||
struct GetAudioContentMainItem: Decodable {
|
||||
let contentId: Int
|
||||
let coverImageUrl: String
|
||||
let title: String
|
||||
let isAdult: Bool
|
||||
let creatorId: Int
|
||||
let creatorProfileImageUrl: String
|
||||
let creatorNickname: String
|
||||
}
|
||||
|
||||
struct GetAudioContentCurationResponse: Decodable {
|
||||
let title: String
|
||||
let description: String
|
||||
let audioContents: [GetAudioContentMainItem]
|
||||
}
|
||||
|
||||
struct GetAudioContentBannerResponse: Decodable {
|
||||
let type: AudioContentBannerType
|
||||
let thumbnailImageUrl: String
|
||||
let eventItem: EventItem?
|
||||
let creatorId: Int?
|
||||
let link: String?
|
||||
}
|
||||
|
||||
enum AudioContentBannerType: String, Decodable {
|
||||
case EVENT, CREATOR, LINK
|
||||
}
|
Reference in New Issue
Block a user