feat(creator): 커뮤니티 아이템 표시를 통일한다

This commit is contained in:
Yu Sung
2026-08-10 15:11:02 +09:00
parent 89c070875c
commit c372d4a522
15 changed files with 1377 additions and 183 deletions

View File

@@ -3,26 +3,22 @@ import SwiftUI
struct CreatorChannelCommunityGridItem: View {
let post: CreatorChannelCommunityPostItem
let isOwnPost: Bool
let onTapPurchase: () -> Void
let onTapDetail: () -> Void
var body: some View {
GeometryReader { proxy in
ZStack {
if isPaidLocked {
Button(action: onTapPurchase) {
Color.gray400
.overlay(paidPriceOverlay)
}
.buttonStyle(.plain)
Color.gray800
.overlay(paidPriceOverlay)
} else {
tileContent(proxy: proxy)
.contentShape(Rectangle())
.onTapGesture(perform: onTapDetail)
}
}
.frame(width: proxy.size.width, height: proxy.size.width)
.clipped()
.contentShape(Rectangle())
.onTapGesture(perform: onTapDetail)
.overlay(alignment: .topTrailing) {
if post.isPinned {
Image("ic_pin")
@@ -92,3 +88,32 @@ struct CreatorChannelCommunityGridItem: View {
return String(content.prefix(18))
}
}
struct CreatorChannelCommunityGridItem_Previews: PreviewProvider {
static var previews: some View {
CreatorChannelCommunityGridItem(
post: CreatorChannelCommunityPostItem(
postId: 1,
creatorId: 10,
creatorNickname: "크리에이터 이름",
creatorProfileUrl: "https://picsum.photos/600",
createdAtUtc: "2026-08-10T00:00:00Z",
content: "유료 커뮤니티 게시글",
imageUrl: nil,
audioUrl: nil,
price: 30,
isCommentAvailable: true,
likeCount: 5,
commentCount: 2,
isPinned: true,
existOrdered: false,
isLiked: false
),
isOwnPost: false,
onTapDetail: {}
)
.frame(width: 134, height: 134)
.background(Color.black)
.previewLayout(.sizeThatFits)
}
}

View File

@@ -9,7 +9,6 @@ struct CreatorChannelCommunityListItem: View {
let isOwnCreatorChannel: Bool
let onTapLike: () -> Void
let onTapMore: () -> Void
let onTapPurchase: () -> Void
let onTapDetail: () -> Void
@State private var localIsLike: Bool
@@ -23,7 +22,6 @@ struct CreatorChannelCommunityListItem: View {
isOwnCreatorChannel: Bool,
onTapLike: @escaping () -> Void,
onTapMore: @escaping () -> Void,
onTapPurchase: @escaping () -> Void,
onTapDetail: @escaping () -> Void
) {
self.post = post
@@ -31,7 +29,6 @@ struct CreatorChannelCommunityListItem: View {
self.isOwnCreatorChannel = isOwnCreatorChannel
self.onTapLike = onTapLike
self.onTapMore = onTapMore
self.onTapPurchase = onTapPurchase
self.onTapDetail = onTapDetail
_localIsLike = State(initialValue: post.isLiked ?? false)
_localLikeCount = State(initialValue: post.likeCount)
@@ -53,7 +50,9 @@ struct CreatorChannelCommunityListItem: View {
imageContent(imageUrl: imageUrl)
}
reactionBar
if !isPaidLocked {
reactionBar
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(SodaSpacing.s14)
@@ -172,14 +171,11 @@ struct CreatorChannelCommunityListItem: View {
}
private var paidLockedImage: some View {
Button(action: onTapPurchase) {
RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous)
.fill(Color.gray400)
.frame(maxWidth: .infinity)
.frame(height: 236)
.overlay(paidPriceOverlay)
}
.buttonStyle(.plain)
RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous)
.fill(Color.gray800)
.frame(maxWidth: .infinity)
.frame(height: 236)
.overlay(paidPriceOverlay)
}
private var paidPriceOverlay: some View {
@@ -219,7 +215,7 @@ struct CreatorChannelCommunityListItem: View {
private var reactionBar: some View {
HStack(spacing: 15) {
if post.isCommentAvailable && !isPaidLocked {
if post.isCommentAvailable {
HStack(spacing: SodaSpacing.s4) {
Image("ic_feed_community_reply")
.resizable()
@@ -231,25 +227,23 @@ struct CreatorChannelCommunityListItem: View {
}
}
if !isPaidLocked {
Button {
localIsLike.toggle()
localLikeCount += localIsLike ? 1 : -1
localLikeCount = max(0, localLikeCount)
onTapLike()
} label: {
HStack(spacing: SodaSpacing.s4) {
Image(localIsLike ? "ic_feed_community_heart_fill" : "ic_feed_community_heart")
.resizable()
.frame(width: 18, height: 18)
Button {
localIsLike.toggle()
localLikeCount += localIsLike ? 1 : -1
localLikeCount = max(0, localLikeCount)
onTapLike()
} label: {
HStack(spacing: SodaSpacing.s4) {
Image(localIsLike ? "ic_feed_community_heart_fill" : "ic_feed_community_heart")
.resizable()
.frame(width: 18, height: 18)
Text("\(localLikeCount)")
.appFont(size: 16, weight: .regular)
.foregroundColor(Color.gray400)
}
Text("\(localLikeCount)")
.appFont(size: 16, weight: .regular)
.foregroundColor(Color.gray400)
}
.buttonStyle(.plain)
}
.buttonStyle(.plain)
}
.frame(height: 24)
}

View File

@@ -4,7 +4,7 @@ struct CreatorChannelCommunityTabView: View {
let creatorId: Int
let isOwnCreatorChannel: Bool
@ObservedObject var viewModel: CreatorChannelCommunityViewModel
let onTapDetail: (CreatorChannelCommunityPostItem) -> Void
let onTapDetail: (Int) -> Void
private let gridColumns = [
GridItem(.flexible(), spacing: 0),
@@ -69,11 +69,8 @@ struct CreatorChannelCommunityTabView: View {
onTapMore: {
viewModel.openReportMenu(post: post)
},
onTapPurchase: {
viewModel.openPurchaseDialog(post: post)
},
onTapDetail: {
onTapDetail(post)
onTapDetail(post.postId)
}
)
.onAppear {
@@ -95,11 +92,8 @@ struct CreatorChannelCommunityTabView: View {
CreatorChannelCommunityGridItem(
post: post,
isOwnPost: isOwnPost,
onTapPurchase: {
viewModel.openPurchaseDialog(post: post)
},
onTapDetail: {
onTapDetail(post)
onTapDetail(post.postId)
}
)
.onAppear {

View File

@@ -50,16 +50,7 @@ final class CreatorChannelCommunityViewModel: ObservableObject {
}
}
}
@Published var isShowPostPurchaseView = false {
didSet {
if !isShowPostPurchaseView {
selectedPostId = 0
selectedPostPrice = 0
}
}
}
@Published var selectedPostId = 0
@Published var selectedPostPrice = 0
@Published var selectedPostIsPinned = false
@Published var isShowSecret = false
@@ -94,17 +85,10 @@ final class CreatorChannelCommunityViewModel: ObservableObject {
func openReportMenu(post: CreatorChannelCommunityPostItem) {
selectedPostId = post.postId
selectedPostPrice = post.price
selectedPostIsPinned = post.isPinned
isShowReportMenu = true
}
func openPurchaseDialog(post: CreatorChannelCommunityPostItem) {
selectedPostId = post.postId
selectedPostPrice = post.price
isShowPostPurchaseView = true
}
func communityPostLike(postId: Int) {
communityRepository.communityPostLike(postId: postId)
.sink { result in
@@ -153,7 +137,7 @@ final class CreatorChannelCommunityViewModel: ObservableObject {
.store(in: &subscription)
}
func deleteCommunityPost(creatorId: Int) {
func deleteCommunityPost(onSuccess: @escaping () -> Void) {
guard selectedPostId > 0 else { return }
isLoading = true
@@ -190,7 +174,7 @@ final class CreatorChannelCommunityViewModel: ObservableObject {
if decoded.success {
self.errorMessage = I18n.Explorer.deleted
self.isShowPopup = true
self.fetchFirstPage(creatorId: creatorId)
onSuccess()
} else {
self.errorMessage = decoded.message ?? I18n.Common.commonError
self.isShowPopup = true
@@ -204,7 +188,7 @@ final class CreatorChannelCommunityViewModel: ObservableObject {
.store(in: &subscription)
}
func updateCommunityPostFixed(creatorId: Int) {
func updateCommunityPostFixed(onSuccess: @escaping () -> Void) {
guard selectedPostId > 0 else { return }
isLoading = true
@@ -228,7 +212,7 @@ final class CreatorChannelCommunityViewModel: ObservableObject {
do {
let decoded = try JSONDecoder().decode(ApiResponseWithoutData.self, from: response.data)
if decoded.success {
self.fetchFirstPage(creatorId: creatorId)
onSuccess()
} else {
self.errorMessage = decoded.message ?? I18n.Common.commonError
self.isShowPopup = true
@@ -242,43 +226,6 @@ final class CreatorChannelCommunityViewModel: ObservableObject {
.store(in: &subscription)
}
func purchaseCommunityPost(creatorId: Int) {
guard selectedPostId > 0 else { return }
isLoading = true
communityRepository.purchaseCommunityPost(postId: selectedPostId)
.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.applyFailureState()
}
} receiveValue: { [weak self] response in
guard let self else { return }
self.isLoading = false
self.selectedPostId = 0
do {
let decoded = try JSONDecoder().decode(ApiResponseWithoutData.self, from: response.data)
if decoded.success {
self.fetchFirstPage(creatorId: creatorId)
} else {
self.errorMessage = decoded.message ?? I18n.Common.commonError
self.isShowPopup = true
}
} catch {
ERROR_LOG(error.localizedDescription)
self.fetchFirstPage(creatorId: creatorId)
}
}
.store(in: &subscription)
}
private func fetchCommunity(creatorId: Int, page requestPage: Int, isNextPage: Bool) {
latestRequestId += 1
let requestId = latestRequestId

View File

@@ -25,7 +25,9 @@ struct CreatorChannelCommunityPostDetailContentView: View {
.frame(maxWidth: .infinity, alignment: .leading)
mediaContent
reactionBar
if !isPaidLocked {
reactionBar
}
}
.padding(SodaSpacing.s14)
.frame(maxWidth: .infinity, alignment: .leading)
@@ -154,32 +156,30 @@ struct CreatorChannelCommunityPostDetailContentView: View {
private var reactionBar: some View {
HStack(spacing: 15) {
if isPaidLocked == false {
if detail.isCommentAvailable {
HStack(spacing: SodaSpacing.s4) {
Image("ic_feed_community_reply")
.resizable()
.frame(width: 18, height: 18)
if detail.isCommentAvailable {
HStack(spacing: SodaSpacing.s4) {
Image("ic_feed_community_reply")
.resizable()
.frame(width: 18, height: 18)
Text("\(detail.commentCount)")
.appFont(size: 16, weight: .regular)
.foregroundColor(Color.gray500)
}
Text("\(detail.commentCount)")
.appFont(size: 16, weight: .regular)
.foregroundColor(Color.gray500)
}
Button(action: onTapLike) {
HStack(spacing: SodaSpacing.s4) {
Image(detail.isLiked ? "ic_feed_community_heart_fill" : "ic_feed_community_heart")
.resizable()
.frame(width: 18, height: 18)
Text("\(detail.likeCount)")
.appFont(size: 16, weight: .regular)
.foregroundColor(Color.gray500)
}
}
.buttonStyle(.plain)
}
Button(action: onTapLike) {
HStack(spacing: SodaSpacing.s4) {
Image(detail.isLiked ? "ic_feed_community_heart_fill" : "ic_feed_community_heart")
.resizable()
.frame(width: 18, height: 18)
Text("\(detail.likeCount)")
.appFont(size: 16, weight: .regular)
.foregroundColor(Color.gray500)
}
}
.buttonStyle(.plain)
}
.frame(height: 24)
}

View File

@@ -19,7 +19,7 @@ struct CreatorChannelCommunityPostDetailView: View {
CreatorChannelCommunityPostDetailContentView(
detail: detail,
onTapLike: viewModel.toggleLike,
onTapPurchase: showPurchaseError
onTapPurchase: viewModel.presentPurchaseDialog
)
if detail.isCommentAvailable {
@@ -69,6 +69,14 @@ struct CreatorChannelCommunityPostDetailView: View {
onDimmedTap: dismissDeleteDialog
)
}
if viewModel.isShowPurchaseDialog, let detail = viewModel.detail {
CommunityPostPurchaseDialog(
isShowing: $viewModel.isShowPurchaseDialog,
can: detail.price,
confirmAction: viewModel.purchaseCommunityPost
)
}
}
.navigationBarBackButtonHidden(true)
.onAppear {
@@ -112,9 +120,4 @@ struct CreatorChannelCommunityPostDetailView: View {
)
}
private func showPurchaseError() {
viewModel.errorMessage = I18n.Common.commonError
viewModel.isShowPopup = true
}
}

View File

@@ -24,6 +24,7 @@ final class CreatorChannelCommunityPostDetailViewModel: ObservableObject {
@Published var editingComment: CreatorChannelCommunityCommentResponse?
@Published var deletingComment: CreatorChannelCommunityCommentResponse?
@Published var isShowDeleteDialog = false
@Published var isShowPurchaseDialog = false
@Published var page = 0
@Published var size = 20
@Published var hasNext = false
@@ -182,6 +183,49 @@ final class CreatorChannelCommunityPostDetailViewModel: ObservableObject {
.store(in: &subscription)
}
func presentPurchaseDialog() {
guard let detail, detail.price > 0, detail.existOrdered == false, isOwnPost == false else { return }
isShowPurchaseDialog = true
}
func purchaseCommunityPost() {
guard postId > 0, isLoading == false else { return }
isLoading = true
communityRepository.purchaseCommunityPost(postId: postId)
.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.applyFailureState()
}
} receiveValue: { [weak self] response in
guard let self else { return }
self.isLoading = false
do {
let decoded = try JSONDecoder().decode(ApiResponseWithoutData.self, from: response.data)
if decoded.success {
self.onCommunityRefresh?()
self.fetchDetail(postId: self.postId)
} else {
self.errorMessage = decoded.message ?? I18n.Common.commonError
self.isShowPopup = true
}
} catch {
ERROR_LOG(error.localizedDescription)
self.errorMessage = I18n.Common.commonError
self.isShowPopup = true
}
}
.store(in: &subscription)
}
func sendComment() {
guard isCommentSendEnabled else { return }