Skip to content

Commit

Permalink
Update other screens using TextView
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jan 3, 2025
1 parent b1709b7 commit d847e8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1068,13 +1068,15 @@ private extension CommentDetailViewController {
return
}

replyTextView?.setShowingLoadingIndicator(true)

commentService.createReply(for: comment, content: content) { reply in
self.commentService.uploadComment(reply, success: { [weak self] in
self?.displayReplyNotice(success: true)
self?.didSendReply(success: true)
self?.refreshCommentReplyIfNeeded()
}, failure: { [weak self] error in
DDLogError("Failed uploading comment reply: \(String(describing: error))")
self?.displayReplyNotice(success: false)
self?.didSendReply(success: false, error: error)
})
}
}
Expand All @@ -1084,21 +1086,30 @@ private extension CommentDetailViewController {
return
}

replyTextView?.setShowingLoadingIndicator(true)

commentService.replyToHierarchicalComment(withID: NSNumber(value: comment.commentID),
post: post,
content: content,
success: { [weak self] in
self?.displayReplyNotice(success: true)
self?.didSendReply(success: true)
self?.refreshCommentReplyIfNeeded()
}, failure: { [weak self] error in
DDLogError("Failed creating post comment reply: \(String(describing: error))")
self?.displayReplyNotice(success: false)
self?.didSendReply(success: false, error: error)
})
}

func displayReplyNotice(success: Bool) {
func didSendReply(success: Bool, error: Error? = nil) {
replyTextView?.setShowingLoadingIndicator(false)
if success {
replyTextView?.text = ""
} else {
replyTextView?.becomeFirstResponder()
}

let message = success ? ReplyMessages.successMessage : ReplyMessages.failureMessage
displayNotice(title: message)
displayNotice(title: message, message: error?.localizedDescription)
}

func configureSuggestionsView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,15 @@ extension NotificationDetailsViewController {
replyTextView.accessibilityIdentifier = .replyTextViewAccessibilityId
replyTextView.accessibilityLabel = NSLocalizedString("Reply Text", comment: "Notifications Reply Accessibility Identifier")
replyTextView.delegate = self
replyTextView.onReply = { [weak self] content in
let group = self?.note.contentGroup(ofKind: .comment)
replyTextView.onReply = { [weak self, weak replyTextView] content in
guard let self, let replyTextView else {
return
}
let group = self.note.contentGroup(ofKind: .comment)
guard let block: FormattableCommentContent = group?.blockOfKind(.comment) else {
return
}
self?.replyCommentWithBlock(block, content: content)
self.replyCommentWithBlock(block, content: content, textView: replyTextView)
}

replyTextView.setContentCompressionResistancePriority(.required, for: .vertical)
Expand Down Expand Up @@ -1085,26 +1088,30 @@ private extension NotificationDetailsViewController {
_ = navigationController?.popToRootViewController(animated: true)
}

func replyCommentWithBlock(_ block: FormattableCommentContent, content: String) {
func replyCommentWithBlock(_ block: FormattableCommentContent, content: String, textView: ReplyTextView) {
guard let replyAction = block.action(id: ReplyToCommentAction.actionIdentifier()) else {
return
}

let generator = UINotificationFeedbackGenerator()
generator.prepare()
generator.notificationOccurred(.success)

let actionContext = ActionContext(block: block, content: content) { [weak self] (request, success) in
textView.setShowingLoadingIndicator(false)
if success {
generator.notificationOccurred(.success)
WPAppAnalytics.track(.notificationsCommentRepliedTo)
textView.text = ""
let message = NSLocalizedString("Reply Sent!", comment: "The app successfully sent a comment")
self?.displayNotice(title: message)
} else {
generator.notificationOccurred(.error)
textView.becomeFirstResponder()
self?.displayReplyError(with: block, content: content)
}
}

textView.setShowingLoadingIndicator(true)
replyAction.execute(context: actionContext)
}

Expand Down

0 comments on commit d847e8a

Please sign in to comment.