102 lines
4.0 KiB
Swift
102 lines
4.0 KiB
Swift
import SwiftUI
|
|
|
|
struct MainHomePopularCommunitySection: View {
|
|
let items: [HomePopularCommunityPostItem]
|
|
let onTapCommunity: (Int) -> Void
|
|
let onTapLike: (Int) -> Void
|
|
let onTapPurchase: (HomePopularCommunityPostItem) -> Void
|
|
|
|
init(
|
|
items: [HomePopularCommunityPostItem],
|
|
onTapCommunity: @escaping (Int) -> Void = { _ in },
|
|
onTapLike: @escaping (Int) -> Void = { _ in },
|
|
onTapPurchase: @escaping (HomePopularCommunityPostItem) -> Void = { _ in }
|
|
) {
|
|
self.items = items
|
|
self.onTapCommunity = onTapCommunity
|
|
self.onTapLike = onTapLike
|
|
self.onTapPurchase = onTapPurchase
|
|
}
|
|
|
|
var body: some View {
|
|
if !items.isEmpty {
|
|
VStack(alignment: .leading, spacing: SodaSpacing.s14) {
|
|
SectionTitle(title: I18n.HomeRecommendation.popularCommunitySectionTitle)
|
|
|
|
VStack(alignment: .leading, spacing: SodaSpacing.s8) {
|
|
ForEach(items, id: \.postId) { item in
|
|
CommunityPostCard(
|
|
postId: item.postId,
|
|
creatorNickname: item.creatorNickname,
|
|
creatorProfileImageUrl: item.creatorProfileImage,
|
|
content: item.content,
|
|
imageUrl: item.imageUrl,
|
|
audioUrl: item.audioUrl,
|
|
price: item.price,
|
|
existOrdered: item.existOrdered,
|
|
createdAt: item.relativeCreatedAtText(),
|
|
isLike: item.isLiked,
|
|
likeCount: item.likeCount,
|
|
commentCount: item.commentCount,
|
|
onTapLike: {
|
|
onTapLike(item.postId)
|
|
},
|
|
onTapComment: {
|
|
onTapCommunity(item.creatorId)
|
|
},
|
|
onTapPurchase: {
|
|
onTapPurchase(item)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
.padding(.horizontal, SodaSpacing.s14)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MainHomePopularCommunitySection_Previews: PreviewProvider {
|
|
private static let previewImageUrl = "https://picsum.photos/500/500"
|
|
|
|
static var previews: some View {
|
|
MainHomePopularCommunitySection(
|
|
items: [
|
|
HomePopularCommunityPostItem(
|
|
postId: 1,
|
|
creatorId: 10,
|
|
creatorNickname: "크리에이터 이름",
|
|
creatorProfileImage: previewImageUrl,
|
|
content: "크리에이터가 커뮤니티에 올린 글이 보이는 부분 크리에이터가 커뮤니티에 올린 글이 보이는 부분",
|
|
imageUrl: nil,
|
|
audioUrl: nil,
|
|
price: 0,
|
|
existOrdered: false,
|
|
likeCount: 5,
|
|
commentCount: 6,
|
|
createdAt: "2026-06-29T12:00:00Z",
|
|
isLiked: false
|
|
),
|
|
HomePopularCommunityPostItem(
|
|
postId: 2,
|
|
creatorId: 11,
|
|
creatorNickname: "크리에이터 이름",
|
|
creatorProfileImage: previewImageUrl,
|
|
content: "이미지가 있는 커뮤니티 게시글입니다.",
|
|
imageUrl: previewImageUrl,
|
|
audioUrl: "https://example.com/audio.mp3",
|
|
price: 30,
|
|
existOrdered: false,
|
|
likeCount: 5,
|
|
commentCount: 6,
|
|
createdAt: "2026-06-29T12:00:00Z",
|
|
isLiked: true
|
|
)
|
|
]
|
|
)
|
|
.padding(.vertical, SodaSpacing.s20)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|