Skip to content

Commit

Permalink
Present Comment Moderation Options view
Browse files Browse the repository at this point in the history
  • Loading branch information
salimbraksa committed May 8, 2024
1 parent cf4b51c commit 540aa49
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class CommentDetailViewController: UIViewController, NoResultsViewHost {
return cell
}()

private weak var changeStatusViewController: UIViewController?

// MARK: -

private lazy var commentService: CommentService = {
return .init(coreDataStack: ContextManager.shared)
}()
Expand Down Expand Up @@ -449,8 +453,8 @@ private extension CommentDetailViewController {
editButtonTapped()
case .share:
shareCommentURL(sourceView: cell)
case .changeStatus(let status):
print("Option \(status) tapped")
case .changeStatus:
presentChangeStatusSheet()
}
}
let contentConfig = CommentDetailContentTableViewCell.ContentConfiguration(comment: comment) { [weak self] _ in
Expand Down Expand Up @@ -711,6 +715,20 @@ private extension CommentDetailViewController {
let bottomSheet = BottomSheetViewController(childViewController: viewController, customHeaderSpacing: 0)
bottomSheet.show(from: self)
}

func presentChangeStatusSheet() {
self.changeStatusViewController?.dismiss(animated: false)
let controller = CommentModerationOptionsViewController { [weak self] status in
guard let self else {
return
}
self.updateCommentStatus(status)
self.changeStatusViewController?.dismiss(animated: true)
}
let bottomSheetViewController = BottomSheetViewController(childViewController: controller, customHeaderSpacing: 0)
bottomSheetViewController.show(from: self)
self.changeStatusViewController = bottomSheetViewController
}
}

// MARK: - Strings
Expand Down Expand Up @@ -751,6 +769,15 @@ private extension CommentStatusType {
// MARK: - Comment Moderation Actions

private extension CommentDetailViewController {
func updateCommentStatus(_ status: CommentModerationOptionsView.Option) {
switch status {
case .pending: unapproveComment()
case .approve: approveComment()
case .spam: spamComment()
case .trash: trashComment()
}
}

func unapproveComment() {
isNotificationComment ? WPAppAnalytics.track(.notificationsCommentUnapproved,
withProperties: Constants.notificationDetailSource,
Expand Down

0 comments on commit 540aa49

Please sign in to comment.