feat(creator): 커뮤니티 아이템 표시를 통일한다
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user