커뮤니티 게시물 신고 하기 추가

This commit is contained in:
Yu Sung 2023-12-20 23:27:23 +09:00
parent 302f69b265
commit 9f360e9fcd
5 changed files with 163 additions and 60 deletions

View File

@ -14,6 +14,7 @@ struct CreatorCommunityAllItemView: View {
let onClickLike: () -> Void
let onClickComment: () -> Void
let onClickWriteComment: (String) -> Void
let onClickShowReportMenu: () -> Void
@State var isExpandContent = false
@State var isLike = false
@ -23,12 +24,14 @@ struct CreatorCommunityAllItemView: View {
item: GetCommunityPostListResponse,
onClickLike: @escaping () -> Void,
onClickComment: @escaping () -> Void,
onClickWriteComment: @escaping (String) -> Void
onClickWriteComment: @escaping (String) -> Void,
onClickShowReportMenu: @escaping () -> Void
) {
self.item = item
self.onClickLike = onClickLike
self.onClickComment = onClickComment
self.onClickWriteComment = onClickWriteComment
self.onClickShowReportMenu = onClickShowReportMenu
self._isLike = State(initialValue: item.isLike)
self._likeCount = State(initialValue: item.likeCount)
@ -57,7 +60,7 @@ struct CreatorCommunityAllItemView: View {
Image("ic_seemore_vertical")
.padding(.trailing, 8.3)
.onTapGesture {}
.onTapGesture { onClickShowReportMenu() }
}
Text(item.content)
@ -129,7 +132,8 @@ struct CreatorCommunityAllItemView_Previews: PreviewProvider {
),
onClickLike: {},
onClickComment: {},
onClickWriteComment: { _ in }
onClickWriteComment: { _ in },
onClickShowReportMenu: {}
)
}
}

View File

@ -11,62 +11,114 @@ struct CreatorCommunityAllView: View {
let creatorId: Int
@State private var isShowingReportView = false
@StateObject var viewModel = CreatorCommunityAllViewModel()
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
DetailNavigationBar(title: "커뮤니티")
ScrollView(.vertical, showsIndicators: false) {
LazyVStack(spacing: 26.7) {
ForEach(0..<viewModel.communityPostList.count, id: \.self) { index in
let item = viewModel.communityPostList[index]
CreatorCommunityAllItemView(
item: item,
onClickLike: {
viewModel.communityPostLike(postId: item.postId)
},
onClickComment: {
viewModel.postId = item.postId
},
onClickWriteComment: { comment in
viewModel.createCommunityPostComment(
comment: comment,
postId: item.postId
)
}
)
.onAppear {
if index == viewModel.communityPostList.count - 1 {
viewModel.getCommunityPostList()
GeometryReader { proxy in
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
DetailNavigationBar(title: "커뮤니티")
ScrollView(.vertical, showsIndicators: false) {
LazyVStack(spacing: 26.7) {
ForEach(0..<viewModel.communityPostList.count, id: \.self) { index in
let item = viewModel.communityPostList[index]
CreatorCommunityAllItemView(
item: item,
onClickLike: {
viewModel.communityPostLike(postId: item.postId)
},
onClickComment: {
viewModel.postId = item.postId
viewModel.isShowCommentListView = true
},
onClickWriteComment: { comment in
viewModel.createCommunityPostComment(
comment: comment,
postId: item.postId
)
},
onClickShowReportMenu: {
viewModel.postId = item.postId
viewModel.isShowReportMenu = true
}
)
.onAppear {
if index == viewModel.communityPostList.count - 1 {
viewModel.getCommunityPostList()
}
}
}
}
.padding(5.3)
}
}
.sheet(
isPresented: $viewModel.isShowCommentListView,
content: {
CreatorCommunityCommentListView(
isPresented: $viewModel.isShowCommentListView,
creatorId: creatorId,
postId: viewModel.postId
)
}
)
ZStack {
if viewModel.isShowReportMenu {
VStack(spacing: 0) {
ContentDetailMenuView(
isShowing: $viewModel.isShowReportMenu,
isShowCreatorMenu: creatorId == UserDefaults.int(forKey: .userId),
modifyAction: {
},
deleteAction: {
},
reportAction: {
viewModel.isShowReportView = true
}
)
if proxy.safeAreaInsets.bottom > 0 {
Rectangle()
.foregroundColor(Color(hex: "222222"))
.frame(width: proxy.size.width, height: 15.3)
}
}
.ignoresSafeArea()
}
if viewModel.isShowReportView {
CreatorCommunityReportView(isShowing: $viewModel.isShowReportView) { reason in
viewModel.report(reason: reason)
}
}
if viewModel.isShowDeleteConfirm {
}
.padding(5.3)
}
}
.sheet(
isPresented: $viewModel.isShowCommentListView,
content: {
CreatorCommunityCommentListView(
isPresented: $viewModel.isShowCommentListView,
creatorId: creatorId,
postId: viewModel.postId
)
}
)
if isShowingReportView {
CreatorCommunityReportView(isShowing: $isShowingReportView) { _ in
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
GeometryReader { geo in
HStack {
Spacer()
Text(viewModel.errorMessage)
.padding(.vertical, 13.3)
.frame(width: screenSize().width - 66.7, alignment: .center)
.font(.custom(Font.medium.rawValue, size: 12))
.background(Color(hex: "9970ff"))
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.cornerRadius(20)
.padding(.top, 66.7)
Spacer()
}
}
}
}
.onAppear {
viewModel.creatorId = creatorId
viewModel.getCommunityPostList()
.onAppear {
viewModel.creatorId = creatorId
viewModel.getCommunityPostList()
}
}
}
}

View File

@ -12,6 +12,7 @@ import Combine
class CreatorCommunityAllViewModel: ObservableObject {
private let repository = CreatorCommunityRepository()
private let reportRepository = ReportRepository()
private var subscription = Set<AnyCancellable>()
@Published var isLoading = false
@ -19,13 +20,7 @@ class CreatorCommunityAllViewModel: ObservableObject {
@Published var isShowPopup = false
@Published private(set) var communityPostList = [GetCommunityPostListResponse]()
@Published var postId = 0 {
didSet {
if postId > 0 {
isShowCommentListView = true
}
}
}
@Published var postId = 0
@Published var isShowCommentListView = false {
didSet {
@ -35,6 +30,22 @@ class CreatorCommunityAllViewModel: ObservableObject {
}
}
@Published var isShowReportMenu = false
@Published var isShowReportView = false {
didSet {
if !isShowReportView {
postId = 0
}
}
}
@Published var isShowDeleteConfirm = false {
didSet {
if !isShowDeleteConfirm {
postId = 0
}
}
}
var creatorId = 0
var page = 1
@ -152,4 +163,39 @@ class CreatorCommunityAllViewModel: ObservableObject {
.store(in: &subscription)
}
}
func report(reason: String) {
isLoading = true
let request = ReportRequest(type: .COMMUNITY_POST, reason: reason, communityPostId: postId)
reportRepository.report(request: request)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
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)
}
}

View File

@ -71,8 +71,8 @@ struct CreatorCommunityReportView: View {
.foregroundColor(Color(hex: "9970ff"))
.onTapGesture {
if let selectedIndex = selectedIndex {
isShowing = false
confirmAction(reasons[selectedIndex])
isShowing = false
}
}
}

View File

@ -10,12 +10,13 @@ import Foundation
struct ReportRequest: Encodable {
let type: ReportType
let reason: String
let reportedMemberId: Int?
let cheersId: Int?
let audioContentId: Int?
var reportedMemberId: Int? = nil
var cheersId: Int? = nil
var audioContentId: Int? = nil
var communityPostId: Int? = nil
}
enum ReportType: String, Codable {
case PROFILE, USER, CHEERS, AUDIO_CONTENT
case PROFILE, USER, CHEERS, AUDIO_CONTENT, COMMUNITY_POST
}