feat(creator): 채널 홈 기본 화면을 연결한다
This commit is contained in:
@@ -169,7 +169,7 @@ struct AppStepLayerView: View {
|
||||
LiveReservationCompleteView(reservationCompleteData: response)
|
||||
|
||||
case .creatorDetail(let userId):
|
||||
UserProfileView(userId: userId)
|
||||
CreatorChannelHomeView(creatorId: userId)
|
||||
|
||||
case .followerList(let userId):
|
||||
FollowerListView(userId: userId)
|
||||
|
||||
@@ -3162,6 +3162,42 @@ If you block this user, the following features will be restricted.
|
||||
}
|
||||
}
|
||||
|
||||
enum CreatorChannelHome {
|
||||
static var currentLive: String { pick(ko: "현재 라이브", en: "Live now", ja: "現在ライブ") }
|
||||
static var latestAudio: String { pick(ko: "최신 오디오 콘텐츠", en: "Latest audio", ja: "最新オーディオ") }
|
||||
static var donation: String { pick(ko: "채널 후원", en: "Channel donations", ja: "チャンネル応援") }
|
||||
static var notice: String { pick(ko: "공지", en: "Notice", ja: "お知らせ") }
|
||||
static var schedule: String { pick(ko: "스케줄", en: "Schedule", ja: "スケジュール") }
|
||||
static var audio: String { pick(ko: "오디오", en: "Audio", ja: "オーディオ") }
|
||||
static var series: String { pick(ko: "시리즈", en: "Series", ja: "シリーズ") }
|
||||
static var community: String { pick(ko: "커뮤니티", en: "Community", ja: "コミュニティ") }
|
||||
static var fanTalk: String { pick(ko: "팬Talk", en: "Fan Talk", ja: "ファンTalk") }
|
||||
static var introduce: String { pick(ko: "소개", en: "Introduction", ja: "紹介") }
|
||||
static var activity: String { pick(ko: "활동", en: "Activity", ja: "活動") }
|
||||
static var sns: String { pick(ko: "SNS", en: "SNS", ja: "SNS") }
|
||||
static var follow: String { pick(ko: "팔로우", en: "Follow", ja: "フォロー") }
|
||||
static var following: String { pick(ko: "팔로잉", en: "Following", ja: "フォロー中") }
|
||||
static var talk: String { pick(ko: "대화하기", en: "Start chat", ja: "会話する") }
|
||||
static var viewAll: String { pick(ko: "전체보기", en: "View all", ja: "すべて見る") }
|
||||
static var debut: String { pick(ko: "데뷔", en: "Debut", ja: "デビュー") }
|
||||
static var liveCount: String { pick(ko: "라이브 총 진행 수", en: "Total live count", ja: "ライブ総配信数") }
|
||||
static var liveDurationHours: String { pick(ko: "라이브 누적 진행 시간", en: "Total live hours", ja: "ライブ累計配信時間") }
|
||||
static var liveContributorCount: String { pick(ko: "라이브 누적 참여자", en: "Total live participants", ja: "ライブ累計参加者") }
|
||||
static var audioContentCount: String { pick(ko: "오디오", en: "Audio", ja: "オーディオ") }
|
||||
static var seriesCount: String { pick(ko: "시리즈", en: "Series", ja: "シリーズ") }
|
||||
static var placeholderMessage: String {
|
||||
pick(
|
||||
ko: "준비 중입니다.",
|
||||
en: "Coming soon.",
|
||||
ja: "準備中です。"
|
||||
)
|
||||
}
|
||||
|
||||
static func followerCount(_ count: String) -> String {
|
||||
pick(ko: "팔로워 \(count)명", en: "\(count) followers", ja: "フォロワー\(count)人")
|
||||
}
|
||||
}
|
||||
|
||||
enum HomeRecommendation {
|
||||
static var activityLive: String {
|
||||
pick(ko: "라이브", en: "Live", ja: "ライブ")
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import SwiftUI
|
||||
|
||||
struct CreatorChannelPlaceholderTabView: View {
|
||||
let title: String
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 12) {
|
||||
Text(title)
|
||||
.font(.system(size: 18, weight: .semibold))
|
||||
.foregroundColor(.white)
|
||||
|
||||
Text(I18n.CreatorChannelHome.placeholderMessage)
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(Color.gray500)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(Color.black)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import SwiftUI
|
||||
|
||||
struct CreatorChannelHomeView: View {
|
||||
let creatorId: Int
|
||||
|
||||
@StateObject private var viewModel = CreatorChannelHomeViewModel()
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color.black.ignoresSafeArea()
|
||||
|
||||
VStack(spacing: 0) {
|
||||
titleBar
|
||||
tabBar
|
||||
|
||||
if viewModel.selectedTab != .home || viewModel.isApiFailedPlaceholderVisible {
|
||||
CreatorChannelPlaceholderTabView(title: viewModel.selectedTab.title)
|
||||
} else {
|
||||
homeContent
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.isLoading {
|
||||
LoadingView()
|
||||
}
|
||||
}
|
||||
.navigationBarBackButtonHidden(true)
|
||||
.onAppear {
|
||||
if viewModel.hasLoaded == false {
|
||||
viewModel.fetchHome(creatorId: creatorId)
|
||||
}
|
||||
}
|
||||
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 1)
|
||||
}
|
||||
|
||||
private var titleBar: some View {
|
||||
HStack(spacing: 12) {
|
||||
Button {
|
||||
dismiss()
|
||||
} label: {
|
||||
Image(systemName: "chevron.left")
|
||||
.foregroundColor(.white)
|
||||
.frame(width: 44, height: 44)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
if let creator = viewModel.response?.creator {
|
||||
Button {
|
||||
if creator.isFollow {
|
||||
viewModel.unfollow(creatorId: creator.creatorId)
|
||||
} else {
|
||||
viewModel.follow(creatorId: creator.creatorId, notify: true)
|
||||
}
|
||||
} label: {
|
||||
Text(creator.isFollow ? I18n.CreatorChannelHome.following : I18n.CreatorChannelHome.follow)
|
||||
.font(.system(size: 13, weight: .semibold))
|
||||
.foregroundColor(creator.isFollow ? .white : .black)
|
||||
.padding(.horizontal, 12)
|
||||
.frame(height: 30)
|
||||
.background(creator.isFollow ? Color.gray33 : Color.soda400)
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: 56)
|
||||
.padding(.horizontal, 8)
|
||||
.background(Color.black)
|
||||
}
|
||||
|
||||
private var tabBar: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: 20) {
|
||||
ForEach(CreatorChannelHomeTab.allCases, id: \.self) { tab in
|
||||
Button {
|
||||
viewModel.selectedTab = tab
|
||||
} label: {
|
||||
VStack(spacing: 8) {
|
||||
Text(tab.title)
|
||||
.font(.system(size: 15, weight: viewModel.selectedTab == tab ? .semibold : .regular))
|
||||
.foregroundColor(viewModel.selectedTab == tab ? .white : Color.gray500)
|
||||
|
||||
Rectangle()
|
||||
.fill(viewModel.selectedTab == tab ? Color.soda400 : Color.clear)
|
||||
.frame(height: 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
}
|
||||
.frame(height: 48)
|
||||
.background(Color.black)
|
||||
}
|
||||
|
||||
private var homeContent: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
if let creator = viewModel.response?.creator {
|
||||
Text(creator.nickname)
|
||||
.font(.system(size: 24, weight: .bold))
|
||||
.foregroundColor(.white)
|
||||
|
||||
Text(I18n.CreatorChannelHome.followerCount(creator.followerCount.comma()))
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(Color.gray500)
|
||||
} else {
|
||||
CreatorChannelPlaceholderTabView(title: CreatorChannelHomeTab.home.title)
|
||||
.frame(minHeight: 240)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(20)
|
||||
}
|
||||
.background(Color.black)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class CreatorChannelHomeViewModel: ObservableObject {
|
||||
private let repository = CreatorChannelHomeRepository()
|
||||
private let userRepository = UserRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var isLoading = false
|
||||
@Published var response: CreatorChannelHomeResponse?
|
||||
@Published var hasLoaded = false
|
||||
@Published var selectedTab: CreatorChannelHomeTab = .home
|
||||
@Published var isApiFailedPlaceholderVisible = false
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
|
||||
func fetchHome(creatorId: Int) {
|
||||
isLoading = true
|
||||
isApiFailedPlaceholderVisible = false
|
||||
|
||||
repository.getHome(creatorId: creatorId)
|
||||
.sink { [weak self] result in
|
||||
guard let self else { return }
|
||||
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.applyApiFailedPlaceholderState()
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self else { return }
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<CreatorChannelHomeResponse>.self, from: response.data)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.response = data
|
||||
self.selectedTab = .home
|
||||
self.isApiFailedPlaceholderVisible = false
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
ERROR_LOG(message)
|
||||
}
|
||||
self.applyApiFailedPlaceholderState()
|
||||
}
|
||||
} catch {
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.applyApiFailedPlaceholderState()
|
||||
}
|
||||
|
||||
self.hasLoaded = true
|
||||
self.isLoading = false
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func follow(creatorId: Int, notify: Bool = true) {
|
||||
isLoading = true
|
||||
|
||||
userRepository.creatorFollow(creatorId: creatorId, follow: true, notify: notify)
|
||||
.sink { [weak self] result in
|
||||
guard let self else { return }
|
||||
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.isLoading = false
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self else { return }
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: response.data)
|
||||
|
||||
if decoded.success {
|
||||
self.updateCreatorFollowState(isFollow: true, isNotify: notify)
|
||||
} else {
|
||||
self.errorMessage = decoded.message ?? I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
|
||||
self.isLoading = false
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func unfollow(creatorId: Int) {
|
||||
isLoading = true
|
||||
|
||||
userRepository.creatorUnFollow(creatorId: creatorId)
|
||||
.sink { [weak self] result in
|
||||
guard let self else { return }
|
||||
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.isLoading = false
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self else { return }
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: response.data)
|
||||
|
||||
if decoded.success {
|
||||
self.updateCreatorFollowState(isFollow: false, isNotify: false)
|
||||
} else {
|
||||
self.errorMessage = decoded.message ?? I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
|
||||
self.isLoading = false
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func applyApiFailedPlaceholderState() {
|
||||
response = nil
|
||||
isApiFailedPlaceholderVisible = true
|
||||
hasLoaded = true
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
private func updateCreatorFollowState(isFollow: Bool, isNotify: Bool) {
|
||||
response?.creator.isFollow = isFollow
|
||||
response?.creator.isNotify = isNotify
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
import Foundation
|
||||
|
||||
struct CreatorChannelHomeResponse: Decodable {
|
||||
var creator: CreatorChannelCreatorResponse
|
||||
let currentLive: CreatorChannelLiveResponse?
|
||||
let latestAudioContent: CreatorChannelAudioContentResponse?
|
||||
let channelDonations: [CreatorChannelDonationResponse]
|
||||
let notices: [CreatorChannelCommunityPostResponse]
|
||||
let schedules: [CreatorChannelScheduleResponse]
|
||||
let audioContents: [CreatorChannelAudioContentResponse]
|
||||
let series: [CreatorChannelSeriesResponse]
|
||||
let communities: [CreatorChannelCommunityPostResponse]
|
||||
let fanTalk: CreatorChannelFanTalkSummaryResponse
|
||||
let introduce: String
|
||||
let activity: CreatorChannelActivityResponse
|
||||
let sns: CreatorChannelSnsResponse
|
||||
}
|
||||
|
||||
struct CreatorChannelCreatorResponse: Decodable, Identifiable {
|
||||
let creatorId: Int
|
||||
let nickname: String
|
||||
let profileImageUrl: String?
|
||||
let followerCount: Int
|
||||
let characterId: Int?
|
||||
var isFollow: Bool
|
||||
var isNotify: Bool
|
||||
let isAiChatAvailable: Bool
|
||||
let isDmAvailable: Bool
|
||||
|
||||
var id: Int { creatorId }
|
||||
}
|
||||
|
||||
struct CreatorChannelLiveResponse: Decodable, Identifiable {
|
||||
let liveId: Int
|
||||
let title: String
|
||||
let coverImageUrl: String?
|
||||
let beginDateTimeUtc: String
|
||||
let price: Int
|
||||
let isAdult: Bool
|
||||
|
||||
var id: Int { liveId }
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioContentResponse: Decodable, Identifiable {
|
||||
let audioContentId: Int
|
||||
let title: String
|
||||
let duration: Int
|
||||
let imageUrl: String?
|
||||
let price: Int
|
||||
let isAdult: Bool
|
||||
let isPointAvailable: Bool
|
||||
let isFirstContent: Bool
|
||||
let seriesName: String?
|
||||
let isOriginalSeries: Bool
|
||||
|
||||
var id: Int { audioContentId }
|
||||
}
|
||||
|
||||
struct CreatorChannelDonationResponse: Decodable, Identifiable {
|
||||
let donationId: Int
|
||||
let nickname: String
|
||||
let profileImageUrl: String?
|
||||
let can: Int
|
||||
let message: String
|
||||
let createdAtUtc: String
|
||||
|
||||
var id: Int { donationId }
|
||||
}
|
||||
|
||||
struct CreatorChannelScheduleResponse: Decodable, Identifiable {
|
||||
let scheduleId: String
|
||||
let scheduledAtUtc: String
|
||||
let title: String
|
||||
let type: CreatorActivityType
|
||||
let targetId: Int
|
||||
|
||||
var id: String { scheduleId }
|
||||
}
|
||||
|
||||
struct CreatorChannelSeriesResponse: Decodable, Identifiable {
|
||||
let seriesId: Int
|
||||
let title: String
|
||||
let coverImageUrl: String?
|
||||
let numberOfContent: Int
|
||||
let isNew: Bool
|
||||
let isOriginal: Bool
|
||||
|
||||
var id: Int { seriesId }
|
||||
}
|
||||
|
||||
struct CreatorChannelCommunityPostResponse: Decodable, Identifiable {
|
||||
let postId: Int
|
||||
let creatorId: Int
|
||||
let creatorNickname: String
|
||||
let creatorProfileImageUrl: String?
|
||||
let content: String
|
||||
let imageUrl: String?
|
||||
let audioUrl: String?
|
||||
let price: Int
|
||||
let existOrdered: Bool
|
||||
let likeCount: Int
|
||||
let commentCount: Int
|
||||
let createdAtUtc: String
|
||||
|
||||
var id: Int { postId }
|
||||
}
|
||||
|
||||
struct CreatorChannelFanTalkSummaryResponse: Decodable {
|
||||
let totalCount: Int
|
||||
let latestFanTalk: CreatorChannelFanTalkResponse?
|
||||
}
|
||||
|
||||
struct CreatorChannelFanTalkResponse: Decodable, Identifiable {
|
||||
let fanTalkId: Int
|
||||
let nickname: String
|
||||
let profileImageUrl: String?
|
||||
let content: String
|
||||
let languageCode: String
|
||||
let createdAtUtc: String
|
||||
|
||||
var id: Int { fanTalkId }
|
||||
}
|
||||
|
||||
struct CreatorChannelActivityResponse: Decodable {
|
||||
let debutDateUtc: String
|
||||
let dDay: Int
|
||||
let liveCount: Int
|
||||
let liveDurationHours: Int
|
||||
let liveContributorCount: Int
|
||||
let audioContentCount: Int
|
||||
let seriesCount: Int
|
||||
}
|
||||
|
||||
struct CreatorChannelSnsResponse: Decodable {
|
||||
let instagramUrl: String?
|
||||
let youtubeUrl: String?
|
||||
let xUrl: String?
|
||||
let kakaoOpenChatUrl: String?
|
||||
let fancimmUrl: String?
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import Foundation
|
||||
|
||||
enum CreatorChannelHomeTab: CaseIterable, Hashable {
|
||||
case home
|
||||
case live
|
||||
case audio
|
||||
case series
|
||||
case community
|
||||
case fanTalk
|
||||
case donation
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .home:
|
||||
return "홈"
|
||||
case .live:
|
||||
return "라이브"
|
||||
case .audio:
|
||||
return "오디오"
|
||||
case .series:
|
||||
return "시리즈"
|
||||
case .community:
|
||||
return "커뮤니티"
|
||||
case .fanTalk:
|
||||
return "팬Talk"
|
||||
case .donation:
|
||||
return "후원"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import Foundation
|
||||
|
||||
import Moya
|
||||
|
||||
enum CreatorChannelHomeApi {
|
||||
case getHome(creatorId: Int)
|
||||
}
|
||||
|
||||
extension CreatorChannelHomeApi: TargetType {
|
||||
var baseURL: URL {
|
||||
return URL(string: BASE_URL)!
|
||||
}
|
||||
|
||||
var path: String {
|
||||
switch self {
|
||||
case .getHome(let creatorId):
|
||||
return "/api/v2/creator-channels/\(creatorId)/home"
|
||||
}
|
||||
}
|
||||
|
||||
var method: Moya.Method {
|
||||
switch self {
|
||||
case .getHome:
|
||||
return .get
|
||||
}
|
||||
}
|
||||
|
||||
var task: Moya.Task {
|
||||
switch self {
|
||||
case .getHome:
|
||||
return .requestPlain
|
||||
}
|
||||
}
|
||||
|
||||
var headers: [String: String]? {
|
||||
return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
import CombineMoya
|
||||
import Moya
|
||||
|
||||
final class CreatorChannelHomeRepository {
|
||||
private let api = MoyaProvider<CreatorChannelHomeApi>()
|
||||
|
||||
func getHome(creatorId: Int) -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(.getHome(creatorId: creatorId))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user