diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift index 26ce005..c9cb5fa 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift @@ -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: {} ) } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllView.swift index 4c71bb6..af1aa2b 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllView.swift @@ -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.. 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() + } } } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllViewModel.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllViewModel.swift index a93b9f2..43d5718 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllViewModel.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllViewModel.swift @@ -12,6 +12,7 @@ import Combine class CreatorCommunityAllViewModel: ObservableObject { private let repository = CreatorCommunityRepository() + private let reportRepository = ReportRepository() private var subscription = Set() @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) + } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/Report/CreatorCommunityReportView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/Report/CreatorCommunityReportView.swift index 68f386f..88bb141 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/Report/CreatorCommunityReportView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/Report/CreatorCommunityReportView.swift @@ -71,8 +71,8 @@ struct CreatorCommunityReportView: View { .foregroundColor(Color(hex: "9970ff")) .onTapGesture { if let selectedIndex = selectedIndex { - isShowing = false confirmAction(reasons[selectedIndex]) + isShowing = false } } } diff --git a/SodaLive/Sources/Report/ReportRequest.swift b/SodaLive/Sources/Report/ReportRequest.swift index 9333eb0..0df7485 100644 --- a/SodaLive/Sources/Report/ReportRequest.swift +++ b/SodaLive/Sources/Report/ReportRequest.swift @@ -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 }