119 lines
4.7 KiB
Swift
119 lines
4.7 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorChannelCommunitySection: View {
|
|
let communities: [CreatorChannelCommunityPostResponse]
|
|
let onSelectTab: (CreatorChannelTab) -> Void
|
|
let onTapLike: (Int) -> Void
|
|
let onTapComment: (Int) -> Void
|
|
let onTapPurchase: (CreatorChannelCommunityPostResponse) -> Void
|
|
|
|
private let homeVisibleCount = 3
|
|
|
|
init(
|
|
communities: [CreatorChannelCommunityPostResponse],
|
|
onSelectTab: @escaping (CreatorChannelTab) -> Void,
|
|
onTapLike: @escaping (Int) -> Void = { _ in },
|
|
onTapComment: @escaping (Int) -> Void = { _ in },
|
|
onTapPurchase: @escaping (CreatorChannelCommunityPostResponse) -> Void = { _ in }
|
|
) {
|
|
self.communities = communities
|
|
self.onSelectTab = onSelectTab
|
|
self.onTapLike = onTapLike
|
|
self.onTapComment = onTapComment
|
|
self.onTapPurchase = onTapPurchase
|
|
}
|
|
|
|
var body: some View {
|
|
if communities.isEmpty == false {
|
|
VStack(alignment: .leading, spacing: SodaSpacing.s14) {
|
|
SectionTitle(title: I18n.CreatorChannelHome.community)
|
|
|
|
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,
|
|
onTapLike: {
|
|
onTapLike(community.postId)
|
|
},
|
|
onTapComment: {
|
|
onTapComment(community.postId)
|
|
},
|
|
onTapPurchase: {
|
|
onTapPurchase(community)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
.padding(.horizontal, SodaSpacing.s14)
|
|
|
|
Button {
|
|
onSelectTab(.community)
|
|
} label: {
|
|
Text(I18n.CreatorChannelHome.viewAll)
|
|
.appFont(size: 16, weight: .medium)
|
|
.foregroundColor(.white)
|
|
.frame(maxWidth: .infinity)
|
|
.frame(height: 44)
|
|
.overlay(
|
|
Capsule()
|
|
.stroke(Color.white.opacity(0.3), lineWidth: 1)
|
|
)
|
|
}
|
|
.buttonStyle(.plain)
|
|
.padding(.horizontal, SodaSpacing.s14)
|
|
}
|
|
.padding(.top, SodaSpacing.s20)
|
|
}
|
|
}
|
|
|
|
private var visibleCommunities: [CreatorChannelCommunityPostResponse] {
|
|
Array(communities.prefix(homeVisibleCount))
|
|
}
|
|
}
|
|
|
|
private extension CreatorChannelCommunityPostResponse {
|
|
func relativeTimeText(now: Date = Date()) -> String {
|
|
DateParser.relativeTimeText(fromUTC: dateUtc, fallback: dateUtc, now: now)
|
|
}
|
|
}
|
|
|
|
struct CreatorChannelCommunitySection_Previews: PreviewProvider {
|
|
private static let previewImageUrl = "https://picsum.photos/500/500"
|
|
|
|
static var previews: some View {
|
|
CreatorChannelCommunitySection(
|
|
communities: (1...3).map { index in
|
|
CreatorChannelCommunityPostResponse(
|
|
postId: index,
|
|
creatorId: 10,
|
|
creatorNickname: "크리에이터 이름",
|
|
creatorProfileUrl: previewImageUrl,
|
|
imageUrl: index == 1 ? nil : previewImageUrl,
|
|
audioUrl: nil,
|
|
content: "크리에이터가 커뮤니티에 올린 글이 보이는 부분 크리에이터가 커뮤니티에 올린 글이 보이는 부분",
|
|
price: index == 2 ? 30 : 0,
|
|
dateUtc: "2026-07-03T03:44:00Z",
|
|
existOrdered: false,
|
|
likeCount: 5,
|
|
commentCount: 6,
|
|
isLiked: false
|
|
)
|
|
},
|
|
onSelectTab: { _ in }
|
|
)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|