feat(creator): 커뮤니티 아이템 표시를 통일한다
This commit is contained in:
@@ -2,25 +2,28 @@ import SwiftUI
|
||||
|
||||
struct CreatorChannelCommunitySection: View {
|
||||
let communities: [CreatorChannelCommunityPostResponse]
|
||||
let isOwnCreatorChannel: Bool
|
||||
let onSelectTab: (CreatorChannelTab) -> Void
|
||||
let onTapLike: (Int) -> Void
|
||||
let onTapComment: (Int) -> Void
|
||||
let onTapPurchase: (CreatorChannelCommunityPostResponse) -> Void
|
||||
let onTapMore: (CreatorChannelCommunityPostItem) -> Void
|
||||
let onTapDetail: (Int) -> Void
|
||||
|
||||
private let homeVisibleCount = 3
|
||||
|
||||
init(
|
||||
communities: [CreatorChannelCommunityPostResponse],
|
||||
isOwnCreatorChannel: Bool,
|
||||
onSelectTab: @escaping (CreatorChannelTab) -> Void,
|
||||
onTapLike: @escaping (Int) -> Void = { _ in },
|
||||
onTapComment: @escaping (Int) -> Void = { _ in },
|
||||
onTapPurchase: @escaping (CreatorChannelCommunityPostResponse) -> Void = { _ in }
|
||||
onTapMore: @escaping (CreatorChannelCommunityPostItem) -> Void = { _ in },
|
||||
onTapDetail: @escaping (Int) -> Void = { _ in }
|
||||
) {
|
||||
self.communities = communities
|
||||
self.isOwnCreatorChannel = isOwnCreatorChannel
|
||||
self.onSelectTab = onSelectTab
|
||||
self.onTapLike = onTapLike
|
||||
self.onTapComment = onTapComment
|
||||
self.onTapPurchase = onTapPurchase
|
||||
self.onTapMore = onTapMore
|
||||
self.onTapDetail = onTapDetail
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -30,27 +33,21 @@ struct CreatorChannelCommunitySection: View {
|
||||
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s8) {
|
||||
ForEach(visibleCommunities) { community in
|
||||
CommunityPostCard(
|
||||
postId: community.postId,
|
||||
creatorNickname: community.creatorNickname,
|
||||
creatorProfileImageUrl: community.creatorProfileUrl,
|
||||
content: community.content,
|
||||
imageUrl: community.imageUrl,
|
||||
audioUrl: community.audioUrl,
|
||||
price: community.price,
|
||||
existOrdered: community.existOrdered,
|
||||
createdAt: community.relativeTimeText(),
|
||||
isLike: community.isLiked,
|
||||
likeCount: community.likeCount,
|
||||
commentCount: community.commentCount,
|
||||
let post = community.communityPostItem
|
||||
let isOwnPost = post.creatorId == UserDefaults.int(forKey: .userId)
|
||||
|
||||
CreatorChannelCommunityListItem(
|
||||
post: post,
|
||||
isOwnPost: isOwnPost,
|
||||
isOwnCreatorChannel: isOwnCreatorChannel,
|
||||
onTapLike: {
|
||||
onTapLike(community.postId)
|
||||
onTapLike(post.postId)
|
||||
},
|
||||
onTapComment: {
|
||||
onTapComment(community.postId)
|
||||
onTapMore: {
|
||||
onTapMore(post)
|
||||
},
|
||||
onTapPurchase: {
|
||||
onTapPurchase(community)
|
||||
onTapDetail: {
|
||||
onTapDetail(post.postId)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -83,8 +80,24 @@ struct CreatorChannelCommunitySection: View {
|
||||
}
|
||||
|
||||
private extension CreatorChannelCommunityPostResponse {
|
||||
func relativeTimeText(now: Date = Date()) -> String {
|
||||
DateParser.relativeTimeText(fromUTC: dateUtc, fallback: dateUtc, now: now)
|
||||
var communityPostItem: CreatorChannelCommunityPostItem {
|
||||
CreatorChannelCommunityPostItem(
|
||||
postId: postId,
|
||||
creatorId: creatorId,
|
||||
creatorNickname: creatorNickname,
|
||||
creatorProfileUrl: creatorProfileUrl,
|
||||
createdAtUtc: dateUtc,
|
||||
content: content,
|
||||
imageUrl: imageUrl,
|
||||
audioUrl: audioUrl,
|
||||
price: price,
|
||||
isCommentAvailable: isCommentAvailable,
|
||||
likeCount: likeCount,
|
||||
commentCount: commentCount,
|
||||
isPinned: isPinned,
|
||||
existOrdered: existOrdered,
|
||||
isLiked: isLiked
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,10 +120,15 @@ struct CreatorChannelCommunitySection_Previews: PreviewProvider {
|
||||
existOrdered: false,
|
||||
likeCount: 5,
|
||||
commentCount: 6,
|
||||
isLiked: false
|
||||
isLiked: false,
|
||||
isCommentAvailable: index != 3,
|
||||
isPinned: index == 1
|
||||
)
|
||||
},
|
||||
onSelectTab: { _ in }
|
||||
isOwnCreatorChannel: true,
|
||||
onSelectTab: { _ in },
|
||||
onTapMore: { _ in },
|
||||
onTapDetail: { _ in }
|
||||
)
|
||||
.background(Color.black)
|
||||
.previewLayout(.sizeThatFits)
|
||||
|
||||
@@ -264,7 +264,9 @@ struct CreatorChannelNoticeSection_Previews: PreviewProvider {
|
||||
existOrdered: true,
|
||||
likeCount: 5,
|
||||
commentCount: 2,
|
||||
isLiked: false
|
||||
isLiked: false,
|
||||
isCommentAvailable: true,
|
||||
isPinned: true
|
||||
),
|
||||
CreatorChannelCommunityPostResponse(
|
||||
postId: 2,
|
||||
@@ -279,7 +281,9 @@ struct CreatorChannelNoticeSection_Previews: PreviewProvider {
|
||||
existOrdered: false,
|
||||
likeCount: 3,
|
||||
commentCount: 1,
|
||||
isLiked: false
|
||||
isLiked: false,
|
||||
isCommentAvailable: true,
|
||||
isPinned: false
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ import SwiftUI
|
||||
|
||||
struct CreatorChannelHomeView: View {
|
||||
let response: CreatorChannelHomeResponse
|
||||
let isOwnCreatorChannel: Bool
|
||||
let onSelectTab: (CreatorChannelTab) -> Void
|
||||
let onTapLive: (Int) -> Void
|
||||
let onTapContent: (Int) -> Void
|
||||
@@ -9,18 +10,24 @@ struct CreatorChannelHomeView: View {
|
||||
let onTapSchedule: (CreatorActivityType, Int) -> Void
|
||||
let onTapSeries: (Int) -> Void
|
||||
let onTapCommunityLike: (Int) -> Void
|
||||
let onTapCommunityMore: (CreatorChannelCommunityPostItem) -> Void
|
||||
let onTapCommunityDetail: (Int) -> Void
|
||||
|
||||
init(
|
||||
response: CreatorChannelHomeResponse,
|
||||
isOwnCreatorChannel: Bool,
|
||||
onSelectTab: @escaping (CreatorChannelTab) -> Void,
|
||||
onTapLive: @escaping (Int) -> Void = { _ in },
|
||||
onTapContent: @escaping (Int) -> Void = { _ in },
|
||||
onTapDonate: @escaping () -> Void = {},
|
||||
onTapSchedule: @escaping (CreatorActivityType, Int) -> Void = { _, _ in },
|
||||
onTapSeries: @escaping (Int) -> Void = { _ in },
|
||||
onTapCommunityLike: @escaping (Int) -> Void = { _ in }
|
||||
onTapCommunityLike: @escaping (Int) -> Void = { _ in },
|
||||
onTapCommunityMore: @escaping (CreatorChannelCommunityPostItem) -> Void = { _ in },
|
||||
onTapCommunityDetail: @escaping (Int) -> Void = { _ in }
|
||||
) {
|
||||
self.response = response
|
||||
self.isOwnCreatorChannel = isOwnCreatorChannel
|
||||
self.onSelectTab = onSelectTab
|
||||
self.onTapLive = onTapLive
|
||||
self.onTapContent = onTapContent
|
||||
@@ -28,6 +35,8 @@ struct CreatorChannelHomeView: View {
|
||||
self.onTapSchedule = onTapSchedule
|
||||
self.onTapSeries = onTapSeries
|
||||
self.onTapCommunityLike = onTapCommunityLike
|
||||
self.onTapCommunityMore = onTapCommunityMore
|
||||
self.onTapCommunityDetail = onTapCommunityDetail
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -69,8 +78,11 @@ struct CreatorChannelHomeView: View {
|
||||
|
||||
CreatorChannelCommunitySection(
|
||||
communities: response.communities,
|
||||
isOwnCreatorChannel: isOwnCreatorChannel,
|
||||
onSelectTab: onSelectTab,
|
||||
onTapLike: onTapCommunityLike
|
||||
onTapLike: onTapCommunityLike,
|
||||
onTapMore: onTapCommunityMore,
|
||||
onTapDetail: onTapCommunityDetail
|
||||
)
|
||||
|
||||
CreatorChannelFanTalkSection(
|
||||
|
||||
@@ -98,6 +98,8 @@ struct CreatorChannelCommunityPostResponse: Decodable, Identifiable {
|
||||
let likeCount: Int
|
||||
let commentCount: Int
|
||||
let isLiked: Bool
|
||||
let isCommentAvailable: Bool
|
||||
let isPinned: Bool
|
||||
|
||||
var id: Int { postId }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user