Skip to content

Commit

Permalink
[MBL-1021] Block User Action Sheet (#1874)
Browse files Browse the repository at this point in the history
* create BlockUserActionSheetView

* present action sheet when tapping creator cell on project screen

* gated behind featureBlockUsersEnabled()
* goes directly to creator profile if flag is false. this is the current app behavior

* formatting

* show action sheet when tapping top-level comment cell header

* give action sheet view a tag so that we can avoid adding to the view stack multiple times

* present actions sheet on reply comment cell header tap

* present action sheet when tapping MessageCell header from within a message

* created a new outlet from Message.storyboard so that we can present the action sheet when the message sender's avatar, name, or project name is tapped
* includes MessageCellViewModel test

* update todo comments with ticket links

* remove SwiftUI view and build action sheet using UIAlertController

* added a custom helper in our UIAlertController extension

* add accessibility identifier and value to alert controller

* Increase shallow fetch depth to 100, to make Danger work

* reference UIUserInterfaceSizeClass.horizontalSizeClass instead of userInterfaceIdiom

* cleanup

* update RootCommentCell

* also includes some further delegate naming cleanup

* format

---------

Co-authored-by: Amy <a.dyer@kickstarter.com>
  • Loading branch information
scottkicks and amy-at-kickstarter committed Nov 2, 2023
1 parent 7588768 commit 0272dca
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 33 deletions.
Expand Up @@ -160,6 +160,23 @@ final class CommentRepliesViewController: UITableViewController {
}
}
}

private func blockUser() {
// Scott TODO: present popup UI [mbl-1036](https://kickstarter.atlassian.net/browse/MBL-1036)
}

private func handleCommentCellHeaderTapped(in cell: UITableViewCell, _: Comment.Author) {
guard AppEnvironment.current.currentUser != nil, featureBlockUsersEnabled() else { return }

let actionSheet = UIAlertController
.blockUserActionSheet(
blockUserHandler: { _ in self.blockUser() },
sourceView: cell,
isIPad: self.traitCollection.horizontalSizeClass == .regular
)

self.present(actionSheet, animated: true)
}
}

// MARK: - UITableViewDelegate
Expand All @@ -179,6 +196,11 @@ extension CommentRepliesViewController {
self.viewModel.inputs.didSelectComment(comment)
}
}

override func tableView(_: UITableView, willDisplay cell: UITableViewCell, forRowAt _: IndexPath) {
(cell as? RootCommentCell)?.delegate = self
(cell as? CommentCell)?.delegate = self
}
}

// MARK: - CommentComposerViewDelegate
Expand All @@ -189,6 +211,26 @@ extension CommentRepliesViewController: CommentComposerViewDelegate {
}
}

// MARK: - CommentCellDelegate

extension CommentRepliesViewController: CommentCellDelegate {
func commentCellDidTapHeader(_ cell: CommentCell, _ author: Comment.Author) {
self.handleCommentCellHeaderTapped(in: cell, author)
}

func commentCellDidTapReply(_: CommentCell, comment _: Comment) {}

func commentCellDidTapViewReplies(_: CommentCell, comment _: Comment) {}
}

// MARK: - RootCommentCellDelegate

extension CommentRepliesViewController: RootCommentCellDelegate {
func commentCellDidTapHeader(_ cell: RootCommentCell, _ author: Comment.Author) {
self.handleCommentCellHeaderTapped(in: cell, author)
}
}

// MARK: - Styles

private let tableViewStyle: TableViewStyle = { tableView in
Expand Down
Expand Up @@ -179,6 +179,10 @@ internal final class CommentsViewController: UITableViewController {
}
}

private func blockUser() {
// Scott TODO: present popup ui
}

// MARK: - Actions

@objc private func refresh() {
Expand Down Expand Up @@ -237,6 +241,19 @@ extension CommentsViewController {
// MARK: - CommentCellDelegate

extension CommentsViewController: CommentCellDelegate {
func commentCellDidTapHeader(_ cell: CommentCell, _: Comment.Author) {
guard AppEnvironment.current.currentUser != nil, featureBlockUsersEnabled() else { return }

let actionSheet = UIAlertController
.blockUserActionSheet(
blockUserHandler: { _ in self.blockUser() },
sourceView: cell,
isIPad: self.traitCollection.horizontalSizeClass == .regular
)

self.present(actionSheet, animated: true)
}

func commentCellDidTapReply(_: CommentCell, comment: Comment) {
self.viewModel.inputs.commentCellDidTapReply(comment: comment)
}
Expand Down
16 changes: 16 additions & 0 deletions Kickstarter-iOS/Features/Comments/Views/Cells/CommentCell.swift
Expand Up @@ -4,6 +4,7 @@ import Prelude
import UIKit

protocol CommentCellDelegate: AnyObject {
func commentCellDidTapHeader(_ cell: CommentCell, _ author: Comment.Author)
func commentCellDidTapReply(_ cell: CommentCell, comment: Comment)
func commentCellDidTapViewReplies(_ cell: CommentCell, comment: Comment)
}
Expand Down Expand Up @@ -44,6 +45,10 @@ final class CommentCell: UITableViewCell, ValueCell {
self.bindViewModel()

self.replyButton.addTarget(self, action: #selector(self.replyButtonTapped), for: .touchUpInside)
self.commentCellHeaderStackView.addGestureRecognizer(UITapGestureRecognizer(
target: self,
action: #selector(self.commentCellHeaderTapped)
))
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -60,6 +65,10 @@ final class CommentCell: UITableViewCell, ValueCell {
self.viewModel.inputs.viewRepliesButtonTapped()
}

@objc private func commentCellHeaderTapped() {
self.viewModel.inputs.cellHeaderTapped()
}

// MARK: - Styles

override func bindStyles() {
Expand Down Expand Up @@ -128,6 +137,13 @@ final class CommentCell: UITableViewCell, ValueCell {

self.postedButton.rac.hidden = self.viewModel.outputs.postedButtonIsHidden

self.viewModel.outputs.cellAuthor
.observeForUI()
.observeValues { [weak self] author in
guard let self = self else { return }
self.delegate?.commentCellDidTapHeader(self, author)
}

self.viewModel.outputs.replyCommentTapped
.observeForUI()
.observeValues { [weak self] comment in
Expand Down
Expand Up @@ -9,9 +9,15 @@ private enum Layout {
}
}

protocol RootCommentCellDelegate: AnyObject {
func commentCellDidTapHeader(_ cell: RootCommentCell, _ author: Comment.Author)
}

final class RootCommentCell: UITableViewCell, ValueCell {
// MARK: - Properties

weak var delegate: RootCommentCellDelegate?

private lazy var bodyTextView: UITextView = { UITextView(frame: .zero) }()
private lazy var bottomBorder: UIView = {
UIView(frame: .zero)
Expand All @@ -38,6 +44,11 @@ final class RootCommentCell: UITableViewCell, ValueCell {
self.bindStyles()
self.configureViews()
self.bindViewModel()

self.commentCellHeaderStackView.addGestureRecognizer(UITapGestureRecognizer(
target: self,
action: #selector(self.commentCellHeaderTapped)
))
}

required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -95,5 +106,18 @@ final class RootCommentCell: UITableViewCell, ValueCell {

internal override func bindViewModel() {
self.bodyTextView.rac.text = self.viewModel.outputs.body

self.viewModel.outputs.commentAuthor
.observeForUI()
.observeValues { [weak self] author in
guard let self = self else { return }
self.delegate?.commentCellDidTapHeader(self, author)
}
}

// MARK: - Actions

@objc private func commentCellHeaderTapped() {
self.viewModel.inputs.commentCellHeaderTapped()
}
}
Expand Up @@ -103,9 +103,8 @@ internal final class MessagesViewController: UITableViewController {
}

internal override func tableView(_: UITableView, willDisplay cell: UITableViewCell, forRowAt _: IndexPath) {
if let cell = cell as? BackingCell, cell.delegate == nil {
cell.delegate = self
}
(cell as? BackingCell)?.delegate = self
(cell as? MessageCell)?.delegate = self
}

@IBAction fileprivate func replyButtonPressed() {
Expand Down Expand Up @@ -144,6 +143,10 @@ internal final class MessagesViewController: UITableViewController {
let vc = ManagePledgeViewController.controller(with: params)
self.present(vc, animated: true)
}

private func blockUser() {
// Scott TODO: present popup UI [mbl-1036](https://kickstarter.atlassian.net/browse/MBL-1036)
}
}

extension MessagesViewController: MessageDialogViewControllerDelegate {
Expand All @@ -156,8 +159,27 @@ extension MessagesViewController: MessageDialogViewControllerDelegate {
}
}

// MARK: - BackingCellDelegate

extension MessagesViewController: BackingCellDelegate {
func backingCellGoToBackingInfo() {
self.viewModel.inputs.backingInfoPressed()
}
}

// MARK: - MessageCellDelegate

extension MessagesViewController: MessageCellDelegate {
func messageCellDidTapHeader(_ cell: MessageCell, _: User) {
guard AppEnvironment.current.currentUser != nil, featureBlockUsersEnabled() else { return }

let actionSheet = UIAlertController
.blockUserActionSheet(
blockUserHandler: { _ in self.blockUser() },
sourceView: cell,
isIPad: self.traitCollection.horizontalSizeClass == .regular
)

self.present(actionSheet, animated: true)
}
}

0 comments on commit 0272dca

Please sign in to comment.