Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification Comment details: show loading and error views #18062

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let userInfoCommentIdKey = "commentID"
func nextCommentSelected()
}

class CommentDetailViewController: UIViewController {
class CommentDetailViewController: UIViewController, NoResultsViewHost {

// MARK: Properties

Expand Down Expand Up @@ -247,10 +247,21 @@ class CommentDetailViewController: UIViewController {

// Update the Notification Comment being displayed.
func refreshView(comment: Comment, notification: Notification) {
hideNoResults()
self.notification = notification
displayComment(comment)
}

// Show an empty view with the given values.
func showNoResultsView(title: String, subtitle: String? = nil, imageName: String? = nil, accessoryView: UIView? = nil) {
hideNoResults()
configureAndDisplayNoResults(on: tableView,
title: title,
subtitle: subtitle,
image: imageName,
accessoryView: accessoryView)
}

}

// MARK: - Private Helpers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

class NotificationCommentDetailViewController: UIViewController {
class NotificationCommentDetailViewController: UIViewController, NoResultsViewHost {

// MARK: - Properties

Expand Down Expand Up @@ -159,6 +159,8 @@ private extension NotificationCommentDetailViewController {
}

func loadComment() {
showLoadingView()

fetchParentCommentIfNeeded(completion: { [weak self] in
guard let self = self else {
return
Expand All @@ -169,13 +171,13 @@ private extension NotificationCommentDetailViewController {
return
}

self.fetchComment(self.commentID, completion: { comment in
self.fetchComment(self.commentID, completion: { [weak self] comment in
guard let comment = comment else {
// TODO: show error view
self?.showErrorView()
return
}

self.comment = comment
self?.comment = comment
})
})
}
Expand All @@ -184,7 +186,6 @@ private extension NotificationCommentDetailViewController {
guard let commentID = commentID,
let blog = blog else {
DDLogError("Notification Comment: unable to load comment due to missing information.")
// TODO: show error view
return nil
}

Expand All @@ -195,15 +196,13 @@ private extension NotificationCommentDetailViewController {
guard let commentID = commentID,
let blog = blog else {
DDLogError("Notification Comment: unable to fetch comment due to missing information.")
// TODO: show error view
completion(nil)
return
}

commentService.loadComment(withID: commentID, for: blog, success: { comment in
completion(comment)
}, failure: { error in
// TODO: show error view
completion(nil)
})
}
Expand All @@ -226,4 +225,41 @@ private extension NotificationCommentDetailViewController {
static let arrowButtonSpacing: CGFloat = 12
}

// MARK: - No Results Views

func showLoadingView() {
if let commentDetailViewController = commentDetailViewController {
commentDetailViewController.showNoResultsView(title: NoResults.loadingTitle,
accessoryView: NoResultsViewController.loadingAccessoryView())
} else {
hideNoResults()
configureAndDisplayNoResults(on: view,
title: NoResults.loadingTitle,
accessoryView: NoResultsViewController.loadingAccessoryView())
}
}

func showErrorView() {
if let commentDetailViewController = commentDetailViewController {
commentDetailViewController.showNoResultsView(title: NoResults.errorTitle,
subtitle: NoResults.errorSubtitle,
imageName: NoResults.imageName)
} else {
hideNoResults()
configureAndDisplayNoResults(on: view,
title: NoResults.errorTitle,
subtitle: NoResults.errorSubtitle,
image: NoResults.imageName)


}
}

struct NoResults {
static let loadingTitle = NSLocalizedString("Loading comment...", comment: "Displayed while a comment is being loaded.")
static let errorTitle = NSLocalizedString("Oops", comment: "Title for the view when there's an error loading a comment.")
static let errorSubtitle = NSLocalizedString("There was an error loading the comment.", comment: "Text displayed when there is a failure loading a comment.")
static let imageName = "wp-illustration-notifications"
}

}