fix(main): 최근 활동 이동을 보정한다
This commit is contained in:
@@ -3,17 +3,20 @@ import SwiftUI
|
||||
struct MainHomeActiveCreatorSection: View {
|
||||
let items: [HomeActiveCreatorItem]
|
||||
let onTapLive: (Int) -> Void
|
||||
let onTapCreator: (Int) -> Void
|
||||
let onTapContent: (Int) -> Void
|
||||
let onTapCommunityPost: (Int) -> Void
|
||||
|
||||
init(
|
||||
items: [HomeActiveCreatorItem],
|
||||
onTapLive: @escaping (Int) -> Void = { _ in },
|
||||
onTapCreator: @escaping (Int) -> Void = { _ in },
|
||||
onTapContent: @escaping (Int) -> Void = { _ in },
|
||||
onTapCommunityPost: @escaping (Int) -> Void = { _ in }
|
||||
) {
|
||||
self.items = items
|
||||
self.onTapLive = onTapLive
|
||||
self.onTapCreator = onTapCreator
|
||||
self.onTapContent = onTapContent
|
||||
self.onTapCommunityPost = onTapCommunityPost
|
||||
}
|
||||
@@ -38,16 +41,16 @@ struct MainHomeActiveCreatorSection: View {
|
||||
}
|
||||
|
||||
private func handleTap(_ item: HomeActiveCreatorItem) {
|
||||
guard let targetId = item.targetId else { return }
|
||||
|
||||
switch item.activityType {
|
||||
case .live:
|
||||
onTapLive(targetId)
|
||||
case .audio:
|
||||
onTapContent(targetId)
|
||||
case .community:
|
||||
onTapCommunityPost(targetId)
|
||||
case .unknown:
|
||||
switch item.activeCreatorTapDestination {
|
||||
case .live(let roomId):
|
||||
onTapLive(roomId)
|
||||
case .creator(let creatorId):
|
||||
onTapCreator(creatorId)
|
||||
case .content(let contentId):
|
||||
onTapContent(contentId)
|
||||
case .communityPost(let postId):
|
||||
onTapCommunityPost(postId)
|
||||
case nil:
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -141,6 +144,7 @@ struct MainHomeActiveCreatorSection_Previews: PreviewProvider {
|
||||
MainHomeActiveCreatorSection(
|
||||
items: [
|
||||
HomeActiveCreatorItem(
|
||||
creatorId: 1,
|
||||
creatorNickname: "크리에이터이름",
|
||||
creatorProfileImage: previewImageUrl,
|
||||
activityType: .live,
|
||||
@@ -148,6 +152,7 @@ struct MainHomeActiveCreatorSection_Previews: PreviewProvider {
|
||||
targetId: 1
|
||||
),
|
||||
HomeActiveCreatorItem(
|
||||
creatorId: 2,
|
||||
creatorNickname: "크리에이터이름",
|
||||
creatorProfileImage: previewImageUrl,
|
||||
activityType: .audio,
|
||||
|
||||
@@ -38,6 +38,7 @@ struct MainHomeRecommendationView: View {
|
||||
MainHomeActiveCreatorSection(
|
||||
items: viewModel.recommendations?.recentlyActiveCreators ?? [],
|
||||
onTapLive: onTapLive,
|
||||
onTapCreator: onTapCreator,
|
||||
onTapContent: onTapContent,
|
||||
onTapCommunityPost: onTapCommunityPost
|
||||
)
|
||||
|
||||
@@ -27,6 +27,7 @@ struct RecommendationBannerResponse: Decodable, Hashable {
|
||||
}
|
||||
|
||||
struct HomeActiveCreatorItem: Decodable, Hashable {
|
||||
let creatorId: Int
|
||||
let creatorNickname: String
|
||||
let creatorProfileImage: String
|
||||
let activityType: RecommendedActivityType
|
||||
@@ -34,6 +35,32 @@ struct HomeActiveCreatorItem: Decodable, Hashable {
|
||||
let targetId: Int?
|
||||
}
|
||||
|
||||
enum HomeActiveCreatorTapDestination: Equatable {
|
||||
case live(Int)
|
||||
case creator(Int)
|
||||
case content(Int)
|
||||
case communityPost(Int)
|
||||
}
|
||||
|
||||
extension HomeActiveCreatorItem {
|
||||
var activeCreatorTapDestination: HomeActiveCreatorTapDestination? {
|
||||
switch activityType {
|
||||
case .live:
|
||||
if let targetId {
|
||||
return .live(targetId)
|
||||
}
|
||||
|
||||
return creatorId > 0 ? .creator(creatorId) : nil
|
||||
case .liveReplay, .audio:
|
||||
return targetId.map(HomeActiveCreatorTapDestination.content)
|
||||
case .community:
|
||||
return targetId.map(HomeActiveCreatorTapDestination.communityPost)
|
||||
case .unknown:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct HomeCreatorItem: Decodable, Hashable {
|
||||
let creatorId: Int
|
||||
let creatorNickname: String
|
||||
|
||||
@@ -2,6 +2,7 @@ import Foundation
|
||||
|
||||
enum RecommendedActivityType: Decodable, Hashable {
|
||||
case live
|
||||
case liveReplay
|
||||
case audio
|
||||
case community
|
||||
case unknown(String)
|
||||
@@ -11,8 +12,10 @@ enum RecommendedActivityType: Decodable, Hashable {
|
||||
let code = try container.decode(String.self)
|
||||
|
||||
switch code {
|
||||
case "LIVE", "LIVE_REPLAY":
|
||||
case "LIVE":
|
||||
self = .live
|
||||
case "LIVE_REPLAY":
|
||||
self = .liveReplay
|
||||
case "AUDIO":
|
||||
self = .audio
|
||||
case "COMMUNITY":
|
||||
@@ -24,7 +27,7 @@ enum RecommendedActivityType: Decodable, Hashable {
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .live:
|
||||
case .live, .liveReplay:
|
||||
return I18n.HomeRecommendation.activityLive
|
||||
case .audio:
|
||||
return I18n.HomeRecommendation.activityAudio
|
||||
|
||||
Reference in New Issue
Block a user