응원글 삭제 기능 추가

This commit is contained in:
Yu Sung 2023-09-09 00:02:39 +09:00
parent b31933715d
commit 5d95c0f1c9
10 changed files with 227 additions and 131 deletions

View File

@ -15,7 +15,7 @@ enum ExplorerApi {
case getFollowerList(userId: Int, page: Int, size: Int) case getFollowerList(userId: Int, page: Int, size: Int)
case getCreatorProfileCheers(userId: Int, page: Int, size: Int) case getCreatorProfileCheers(userId: Int, page: Int, size: Int)
case writeCheers(parentCheersId: Int?, creatorId: Int, content: String) case writeCheers(parentCheersId: Int?, creatorId: Int, content: String)
case modifyCheers(cheersId: Int, content: String) case modifyCheers(request: PutModifyCheersRequest)
case writeCreatorNotice(request: PostCreatorNoticeRequest) case writeCreatorNotice(request: PostCreatorNoticeRequest)
case getCreatorProfileDonationRanking(userId: Int, page: Int, size: Int) case getCreatorProfileDonationRanking(userId: Int, page: Int, size: Int)
} }
@ -102,8 +102,7 @@ extension ExplorerApi: TargetType {
let request = PostWriteCheersRequest(parentId: parentCheersId, creatorId: creatorId, content: content) let request = PostWriteCheersRequest(parentId: parentCheersId, creatorId: creatorId, content: content)
return .requestJSONEncodable(request) return .requestJSONEncodable(request)
case .modifyCheers(let cheersId, let content): case .modifyCheers(let request):
let request = PutModifyCheersRequest(cheersId: cheersId, content: content)
return .requestJSONEncodable(request) return .requestJSONEncodable(request)
case .writeCreatorNotice(let request): case .writeCreatorNotice(let request):

View File

@ -37,8 +37,9 @@ final class ExplorerRepository {
return api.requestPublisher(.writeCheers(parentCheersId: parentCheersId, creatorId: creatorId, content: content)) return api.requestPublisher(.writeCheers(parentCheersId: parentCheersId, creatorId: creatorId, content: content))
} }
func modifyCheers(cheersId: Int, content: String) -> AnyPublisher<Response, MoyaError> { func modifyCheers(cheersId: Int, content: String?, isActive: Bool?) -> AnyPublisher<Response, MoyaError> {
return api.requestPublisher(.modifyCheers(cheersId: cheersId, content: content)) let request = PutModifyCheersRequest(cheersId: cheersId, content: content, isActive: isActive)
return api.requestPublisher(.modifyCheers(request: request))
} }
func writeCreatorNotice(notice: String) -> AnyPublisher<Response, MoyaError> { func writeCreatorNotice(notice: String) -> AnyPublisher<Response, MoyaError> {

View File

@ -15,5 +15,6 @@ struct PostWriteCheersRequest: Encodable {
struct PutModifyCheersRequest: Encodable { struct PutModifyCheersRequest: Encodable {
let cheersId: Int let cheersId: Int
let content: String let content: String?
let isActive: Bool?
} }

View File

@ -81,17 +81,18 @@ struct UserProfileFanTalkAllView: View {
let cheer = viewModel.cheersList[index] let cheer = viewModel.cheersList[index]
UserProfileFanTalkCheersItemView( UserProfileFanTalkCheersItemView(
userId: userId, userId: userId,
cheer: cheer, cheersItem: cheer,
writeCheerReply: { cheersReplyContent in writeCheerReply: { cheersReplyContent in
viewModel.writeCheersReply(parentCheersId: cheer.cheersId, creatorId: userId, cheersReplyContent: cheersReplyContent) viewModel.writeCheersReply(parentCheersId: cheer.cheersId, creatorId: userId, cheersReplyContent: cheersReplyContent)
}, },
modifyCheer: { cheersId, cheersReplyContent in modifyCheer: { cheersId, cheersReplyContent in
viewModel.modifyCheersReply(cheersId: cheersId, creatorId: userId, cheersReplyContent: cheersReplyContent) viewModel.modifyCheers(cheersId: cheersId, creatorId: userId, cheersReplyContent: cheersReplyContent)
}, },
reportPopup: { cheersId in reportPopup: { cheersId in
viewModel.reportCheersId = cheersId viewModel.reportCheersId = cheersId
viewModel.isShowCheersReportMenu = true viewModel.isShowCheersReportMenu = true
} },
onClickDelete: { _ in }
) )
.onAppear { .onAppear {
if index == viewModel.cheersList.count - 1 { if index == viewModel.cheersList.count - 1 {

View File

@ -11,127 +11,176 @@ import Kingfisher
struct UserProfileFanTalkCheersItemView: View { struct UserProfileFanTalkCheersItemView: View {
let userId: Int let userId: Int
let cheer: GetCheersResponseItem let cheersItem: GetCheersResponseItem
let writeCheerReply: (String) -> Void let writeCheerReply: (String) -> Void
let modifyCheer: (Int, String) -> Void let modifyCheer: (Int, String) -> Void
let reportPopup: (Int) -> Void let reportPopup: (Int) -> Void
let onClickDelete: (Int) -> Void
@State var replyContent: String = "" @State var replyContent: String = ""
@State var isShowInputReply = false @State var isShowInputReply = false
@State var isShowPopupMenu: Bool = false
@State var isModeModify: Bool = false
@State var cheers: String = ""
var body: some View { var body: some View {
VStack(alignment: .leading, spacing: 0) { ZStack(alignment: .topTrailing) {
HStack(alignment: .top, spacing: 6.7) { VStack(alignment: .leading, spacing: 0) {
KFImage(URL(string: cheer.profileUrl)) HStack(alignment: .top, spacing: 6.7) {
.cancelOnDisappear(true) KFImage(URL(string: cheersItem.profileUrl))
.downsampling(size: CGSize(width: 33.3, height: 33.3)) .cancelOnDisappear(true)
.resizable() .downsampling(size: CGSize(width: 33.3, height: 33.3))
.frame(width: 33.3, height: 33.3) .resizable()
.clipShape(Circle()) .frame(width: 33.3, height: 33.3)
.clipShape(Circle())
VStack(alignment: .leading, spacing: 0) {
Text("\(cheer.nickname)")
.font(.custom(Font.medium.rawValue, size: 13.3))
.foregroundColor(Color(hex: "eeeeee"))
Text("\(cheer.date)") VStack(alignment: .leading, spacing: 0) {
.font(.custom(Font.medium.rawValue, size: 10.7)) Text("\(cheersItem.nickname)")
.foregroundColor(Color(hex: "525252")) .font(.custom(Font.medium.rawValue, size: 13.3))
.padding(.top, 8.3) .foregroundColor(Color(hex: "eeeeee"))
Text("\(cheer.content)") Text("\(cheersItem.date)")
.font(.custom(Font.medium.rawValue, size: 12)) .font(.custom(Font.medium.rawValue, size: 10.7))
.foregroundColor(Color(hex: "777777")) .foregroundColor(Color(hex: "525252"))
.padding(.top, 13.3) .padding(.top, 8.3)
if isShowInputReply { Text("\(cheersItem.content)")
HStack(spacing: 10) { .font(.custom(Font.medium.rawValue, size: 12))
TextField("응원댓글에 답글을 남겨보세요!", text: $replyContent) .foregroundColor(Color(hex: "777777"))
.autocapitalization(.none) .padding(.top, 13.3)
.disableAutocorrection(true)
.font(.custom(Font.medium.rawValue, size: 13.3)) if isShowInputReply {
.foregroundColor(Color(hex: "eeeeee")) HStack(spacing: 10) {
.padding(13.3) TextField("응원댓글에 답글을 남겨보세요!", text: $replyContent)
.background(Color(hex: "232323")) .autocapitalization(.none)
.accentColor(Color(hex: "9970ff")) .disableAutocorrection(true)
.keyboardType(.default) .font(.custom(Font.medium.rawValue, size: 13.3))
.cornerRadius(10) .foregroundColor(Color(hex: "eeeeee"))
.overlay( .padding(13.3)
RoundedRectangle(cornerRadius: 10) .background(Color(hex: "232323"))
.strokeBorder(lineWidth: 1) .accentColor(Color(hex: "9970ff"))
.foregroundColor(Color(hex: "9970ff")) .keyboardType(.default)
) .cornerRadius(10)
.overlay(
Text("등록") RoundedRectangle(cornerRadius: 10)
.font(.custom(Font.bold.rawValue, size: 13.3)) .strokeBorder(lineWidth: 1)
.foregroundColor(Color(hex: "ffffff")) .foregroundColor(Color(hex: "9970ff"))
.padding(13.3) )
.background(Color(hex: "9970ff"))
.cornerRadius(6.7) Text("등록")
.onTapGesture { .font(.custom(Font.bold.rawValue, size: 13.3))
if cheer.replyList.count > 0 { .foregroundColor(Color(hex: "ffffff"))
modifyCheer(cheer.replyList[0].cheersId, replyContent) .padding(13.3)
} else { .background(Color(hex: "9970ff"))
writeCheerReply(replyContent) .cornerRadius(6.7)
}
}
}
.padding(.top, 10)
} else {
if cheer.replyList.count <= 0 {
if userId == UserDefaults.int(forKey: .userId) {
Text("답글쓰기")
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "9970ff"))
.padding(.top, 18.3)
.onTapGesture { .onTapGesture {
isShowInputReply = true if cheersItem.replyList.count > 0 {
modifyCheer(cheersItem.replyList[0].cheersId, replyContent)
} else {
writeCheerReply(replyContent)
}
} }
} }
.padding(.top, 10)
} else { } else {
let reply = cheer.replyList[0] if cheersItem.replyList.count <= 0 {
VStack(alignment: .leading, spacing: 8.3) { if userId == UserDefaults.int(forKey: .userId) {
Text(reply.content) Text("답글쓰기")
.font(.custom(Font.medium.rawValue, size: 12)) .font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "ffffff")) .foregroundColor(Color(hex: "9970ff"))
.frame(minWidth: 100) .padding(.top, 18.3)
.padding(.horizontal, 6.7) .onTapGesture {
.padding(.vertical, 6.7) isShowInputReply = true
.background(Color(hex: "9970ff").opacity(0.3)) }
.cornerRadius(16.7) }
.padding(.top, 18.3) } else {
let reply = cheersItem.replyList[0]
HStack(spacing: 6.7) { VStack(alignment: .leading, spacing: 8.3) {
Text(reply.date) Text(reply.content)
.font(.custom(Font.medium.rawValue, size: 10.7)) .font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "525252")) .foregroundColor(Color(hex: "ffffff"))
.frame(minWidth: 100)
.padding(.horizontal, 6.7)
.padding(.vertical, 6.7)
.background(Color(hex: "9970ff").opacity(0.3))
.cornerRadius(16.7)
.padding(.top, 18.3)
if userId == UserDefaults.int(forKey: .userId) { HStack(spacing: 6.7) {
Text("답글 수정") Text(reply.date)
.font(.custom(Font.medium.rawValue, size: 10.7)) .font(.custom(Font.medium.rawValue, size: 10.7))
.foregroundColor(Color(hex: "9970ff")) .foregroundColor(Color(hex: "525252"))
.onTapGesture {
self.replyContent = reply.content if userId == UserDefaults.int(forKey: .userId) {
isShowInputReply = true Text("답글 수정")
} .font(.custom(Font.medium.rawValue, size: 10.7))
.foregroundColor(Color(hex: "9970ff"))
.onTapGesture {
self.replyContent = reply.content
isShowInputReply = true
}
}
} }
} }
} }
} }
} }
Spacer()
Image("ic_seemore_vertical")
.onTapGesture { isShowPopupMenu = true }
} }
Spacer() Rectangle()
.frame(height: 1)
Image("ic_seemore_vertical") .foregroundColor(Color(hex: "909090").opacity(0.5))
.onTapGesture { reportPopup(cheer.cheersId) } .padding(.top, 13.3)
} }
.frame(width: screenSize().width - 26.7)
Rectangle() if isShowPopupMenu {
.frame(height: 1) VStack(spacing: 10) {
.foregroundColor(Color(hex: "909090").opacity(0.5)) if cheersItem.memberId != UserDefaults.int(forKey: .userId) {
.padding(.top, 13.3) Text("신고하기")
.font(.custom(Font.medium.rawValue, size: 14))
.foregroundColor(Color(hex: "777777"))
.onTapGesture {
reportPopup(cheersItem.cheersId)
isShowPopupMenu = false
}
}
if cheersItem.memberId == UserDefaults.int(forKey: .userId) {
Text("수정")
.font(.custom(Font.medium.rawValue, size: 14))
.foregroundColor(Color(hex: "777777"))
.onTapGesture {
isModeModify = true
isShowPopupMenu = false
}
}
if userId == UserDefaults.int(forKey: .userId) ||
cheersItem.memberId == UserDefaults.int(forKey: .userId)
{
Text("삭제")
.font(.custom(Font.medium.rawValue, size: 14))
.foregroundColor(Color(hex: "777777"))
.onTapGesture {
onClickDelete(cheersItem.cheersId)
isShowPopupMenu = false
}
}
}
.padding(10)
.background(Color(hex: "222222"))
}
}
.contentShape(Rectangle())
.onTapGesture {
isShowPopupMenu = false
} }
.frame(width: screenSize().width - 26.7)
} }
} }

View File

@ -16,6 +16,7 @@ struct UserProfileFanTalkView: View {
let cheers: GetCheersResponse let cheers: GetCheersResponse
let errorPopup: (String) -> Void let errorPopup: (String) -> Void
let reportPopup: (Int) -> Void let reportPopup: (Int) -> Void
let deletePopup: (Int) -> Void
@Binding var isLoading: Bool @Binding var isLoading: Bool
@State private var cheersContent: String = "" @State private var cheersContent: String = ""
@ -97,15 +98,18 @@ struct UserProfileFanTalkView: View {
let cheer = viewModel.cheersList[$0] let cheer = viewModel.cheersList[$0]
UserProfileFanTalkCheersItemView( UserProfileFanTalkCheersItemView(
userId: userId, userId: userId,
cheer: cheer, cheersItem: cheer,
writeCheerReply: { cheersReplyContent in writeCheerReply: { cheersReplyContent in
viewModel.writeCheersReply(parentCheersId: cheer.cheersId, creatorId: userId, cheersReplyContent: cheersReplyContent) viewModel.writeCheersReply(parentCheersId: cheer.cheersId, creatorId: userId, cheersReplyContent: cheersReplyContent)
}, },
modifyCheer: { cheersId, cheersReplyContent in modifyCheer: { cheersId, cheersReplyContent in
viewModel.modifyCheersReply(cheersId: cheersId, creatorId: userId, cheersReplyContent: cheersReplyContent) viewModel.modifyCheers(cheersId: cheersId, creatorId: userId, cheersReplyContent: cheersReplyContent)
}, },
reportPopup: { cheersId in reportPopup: { cheersId in
reportPopup(cheersId) reportPopup(cheersId)
},
onClickDelete: { cheersId in
deletePopup(cheersId)
} }
) )
.onTapGesture { .onTapGesture {

View File

@ -224,7 +224,7 @@ final class UserProfileFanTalkViewModel: ObservableObject {
.store(in: &subscription) .store(in: &subscription)
} }
func modifyCheersReply(cheersId: Int, creatorId: Int, cheersReplyContent: String) { func modifyCheers(cheersId: Int, creatorId: Int, cheersReplyContent: String) {
if cheersReplyContent.trimmingCharacters(in: .whitespaces).isEmpty { if cheersReplyContent.trimmingCharacters(in: .whitespaces).isEmpty {
if let errorPopup = errorPopup { if let errorPopup = errorPopup {
errorPopup("내용을 입력하세요") errorPopup("내용을 입력하세요")
@ -241,7 +241,7 @@ final class UserProfileFanTalkViewModel: ObservableObject {
} }
isLoading = true isLoading = true
repository.modifyCheers(cheersId: cheersId, content: cheersReplyContent) repository.modifyCheers(cheersId: cheersId, content: cheersReplyContent, isActive: nil)
.sink { result in .sink { result in
switch result { switch result {
case .finished: case .finished:

View File

@ -14,6 +14,7 @@ struct GetCheersResponse: Decodable {
struct GetCheersResponseItem: Decodable { struct GetCheersResponseItem: Decodable {
let cheersId: Int let cheersId: Int
let memberId: Int
let nickname: String let nickname: String
let profileUrl: String let profileUrl: String
let content: String let content: String

View File

@ -174,8 +174,12 @@ struct UserProfileView: View {
viewModel.isShowPopup = true viewModel.isShowPopup = true
}, },
reportPopup: { cheerId in reportPopup: { cheerId in
viewModel.reportCheersId = cheerId viewModel.cheersId = cheerId
viewModel.isShowCheersReportMenu = true viewModel.isShowCheersReportView = true
},
deletePopup: { cheerId in
viewModel.cheersId = cheerId
viewModel.isShowCheersDeleteView = true
}, },
isLoading: $viewModel.isLoading isLoading: $viewModel.isLoading
) )
@ -220,20 +224,18 @@ struct UserProfileView: View {
) )
} }
if viewModel.isShowCheersReportMenu { if viewModel.isShowCheersDeleteView {
VStack(spacing: 0) { SodaDialog(
CheersReportMenuView( title: "응원글 삭제",
isShowing: $viewModel.isShowCheersReportMenu, desc: "삭제하시겠습니까?",
onClickReport: { viewModel.isShowCheersReportView = true } confirmButtonTitle: "삭제",
) confirmButtonAction: {
viewModel.deleteCheers(creatorId: userId)
if proxy.safeAreaInsets.bottom > 0 { viewModel.isShowCheersDeleteView = false
Rectangle() },
.foregroundColor(Color(hex: "222222")) cancelButtonTitle: "취소",
.frame(width: proxy.size.width, height: 15.3) cancelButtonAction: { viewModel.isShowCheersDeleteView = false }
} )
}
.ignoresSafeArea()
} }
if viewModel.isShowCheersReportView { if viewModel.isShowCheersReportView {

View File

@ -47,10 +47,9 @@ final class UserProfileViewModel: ObservableObject {
@Published var isShowUesrReportView = false @Published var isShowUesrReportView = false
@Published var isShowProfileReportConfirm = false @Published var isShowProfileReportConfirm = false
@Published var reportCheersId = 0 @Published var cheersId = 0
@Published var isShowCheersReportMenu = false
@Published var isShowCheersReportView = false @Published var isShowCheersReportView = false
@Published var isShowCheersDeleteView = false
let paymentDialogCancelTitle = "취소" let paymentDialogCancelTitle = "취소"
@ -488,7 +487,7 @@ final class UserProfileViewModel: ObservableObject {
func report(type: ReportType, userId: Int? = nil, reason: String = "프로필 신고") { func report(type: ReportType, userId: Int? = nil, reason: String = "프로필 신고") {
isLoading = true isLoading = true
let request = ReportRequest(type: type, reason: reason, reportedMemberId: userId, cheersId: reportCheersId > 0 && type == .CHEERS ? reportCheersId : nil, audioContentId: nil) let request = ReportRequest(type: type, reason: reason, reportedMemberId: userId, cheersId: cheersId > 0 && type == .CHEERS ? cheersId : nil, audioContentId: nil)
reportRepository.report(request: request) reportRepository.report(request: request)
.sink { result in .sink { result in
switch result { switch result {
@ -501,7 +500,7 @@ final class UserProfileViewModel: ObservableObject {
self.isLoading = false self.isLoading = false
let responseData = response.data let responseData = response.data
self.reportCheersId = 0 self.cheersId = 0
do { do {
let jsonDecoder = JSONDecoder() let jsonDecoder = JSONDecoder()
@ -521,4 +520,43 @@ final class UserProfileViewModel: ObservableObject {
} }
.store(in: &subscription) .store(in: &subscription)
} }
func deleteCheers(creatorId: Int) {
isLoading = true
repository.modifyCheers(cheersId: cheersId, content: nil, isActive: false)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.cheersId = 0
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
self.getCreatorProfile(userId: creatorId)
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
}
.store(in: &subscription)
}
} }