Skip to content

Commit d847e8a

Browse files
committed
Update other screens using TextView
1 parent b1709b7 commit d847e8a

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

WordPress/Classes/ViewRelated/Comments/Controllers/CommentDetailViewController.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,13 +1068,15 @@ private extension CommentDetailViewController {
10681068
return
10691069
}
10701070

1071+
replyTextView?.setShowingLoadingIndicator(true)
1072+
10711073
commentService.createReply(for: comment, content: content) { reply in
10721074
self.commentService.uploadComment(reply, success: { [weak self] in
1073-
self?.displayReplyNotice(success: true)
1075+
self?.didSendReply(success: true)
10741076
self?.refreshCommentReplyIfNeeded()
10751077
}, failure: { [weak self] error in
10761078
DDLogError("Failed uploading comment reply: \(String(describing: error))")
1077-
self?.displayReplyNotice(success: false)
1079+
self?.didSendReply(success: false, error: error)
10781080
})
10791081
}
10801082
}
@@ -1084,21 +1086,30 @@ private extension CommentDetailViewController {
10841086
return
10851087
}
10861088

1089+
replyTextView?.setShowingLoadingIndicator(true)
1090+
10871091
commentService.replyToHierarchicalComment(withID: NSNumber(value: comment.commentID),
10881092
post: post,
10891093
content: content,
10901094
success: { [weak self] in
1091-
self?.displayReplyNotice(success: true)
1095+
self?.didSendReply(success: true)
10921096
self?.refreshCommentReplyIfNeeded()
10931097
}, failure: { [weak self] error in
10941098
DDLogError("Failed creating post comment reply: \(String(describing: error))")
1095-
self?.displayReplyNotice(success: false)
1099+
self?.didSendReply(success: false, error: error)
10961100
})
10971101
}
10981102

1099-
func displayReplyNotice(success: Bool) {
1103+
func didSendReply(success: Bool, error: Error? = nil) {
1104+
replyTextView?.setShowingLoadingIndicator(false)
1105+
if success {
1106+
replyTextView?.text = ""
1107+
} else {
1108+
replyTextView?.becomeFirstResponder()
1109+
}
1110+
11001111
let message = success ? ReplyMessages.successMessage : ReplyMessages.failureMessage
1101-
displayNotice(title: message)
1112+
displayNotice(title: message, message: error?.localizedDescription)
11021113
}
11031114

11041115
func configureSuggestionsView() {

WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,15 @@ extension NotificationDetailsViewController {
417417
replyTextView.accessibilityIdentifier = .replyTextViewAccessibilityId
418418
replyTextView.accessibilityLabel = NSLocalizedString("Reply Text", comment: "Notifications Reply Accessibility Identifier")
419419
replyTextView.delegate = self
420-
replyTextView.onReply = { [weak self] content in
421-
let group = self?.note.contentGroup(ofKind: .comment)
420+
replyTextView.onReply = { [weak self, weak replyTextView] content in
421+
guard let self, let replyTextView else {
422+
return
423+
}
424+
let group = self.note.contentGroup(ofKind: .comment)
422425
guard let block: FormattableCommentContent = group?.blockOfKind(.comment) else {
423426
return
424427
}
425-
self?.replyCommentWithBlock(block, content: content)
428+
self.replyCommentWithBlock(block, content: content, textView: replyTextView)
426429
}
427430

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

1088-
func replyCommentWithBlock(_ block: FormattableCommentContent, content: String) {
1091+
func replyCommentWithBlock(_ block: FormattableCommentContent, content: String, textView: ReplyTextView) {
10891092
guard let replyAction = block.action(id: ReplyToCommentAction.actionIdentifier()) else {
10901093
return
10911094
}
10921095

10931096
let generator = UINotificationFeedbackGenerator()
10941097
generator.prepare()
1095-
generator.notificationOccurred(.success)
10961098

10971099
let actionContext = ActionContext(block: block, content: content) { [weak self] (request, success) in
1100+
textView.setShowingLoadingIndicator(false)
10981101
if success {
1102+
generator.notificationOccurred(.success)
10991103
WPAppAnalytics.track(.notificationsCommentRepliedTo)
1104+
textView.text = ""
11001105
let message = NSLocalizedString("Reply Sent!", comment: "The app successfully sent a comment")
11011106
self?.displayNotice(title: message)
11021107
} else {
11031108
generator.notificationOccurred(.error)
1109+
textView.becomeFirstResponder()
11041110
self?.displayReplyError(with: block, content: content)
11051111
}
11061112
}
11071113

1114+
textView.setShowingLoadingIndicator(true)
11081115
replyAction.execute(context: actionContext)
11091116
}
11101117

0 commit comments

Comments
 (0)