Skip to content

Commit afd1d0c

Browse files
authored
Merge pull request #18548 from wordpress-mobile/feature/18429-dashboard_card_show_error
Blogging Prompt Dashboard Card: show error when fetching prompt fails
2 parents cfeca95 + 47eba2b commit afd1d0c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Prompts/DashboardPromptsCardCell.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
6565
}
6666
}
6767

68+
private var didFailLoadingPrompt: Bool = false {
69+
didSet {
70+
if didFailLoadingPrompt != oldValue {
71+
refreshStackView()
72+
}
73+
}
74+
}
75+
6876
// Used to present:
6977
// - The menu sheet for contextual menu in iOS13.
7078
// - The Blogging Prompts list when selected from the contextual menu.
@@ -320,6 +328,12 @@ private extension DashboardPromptsCardCell {
320328
// clear existing views.
321329
containerStackView.removeAllSubviews()
322330

331+
guard !didFailLoadingPrompt else {
332+
promptLabel.text = Strings.errorTitle
333+
containerStackView.addArrangedSubview(promptTitleView)
334+
return
335+
}
336+
323337
promptLabel.text = forExampleDisplay ? Strings.examplePrompt : prompt?.text.stringByDecodingXMLCharacters().trim()
324338
containerStackView.addArrangedSubview(promptTitleView)
325339

@@ -336,13 +350,16 @@ private extension DashboardPromptsCardCell {
336350
// TODO: check for cached prompt first.
337351

338352
guard let bloggingPromptsService = bloggingPromptsService else {
353+
didFailLoadingPrompt = true
339354
DDLogError("Failed creating BloggingPromptsService instance.")
340355
return
341356
}
342357

343358
bloggingPromptsService.fetchTodaysPrompt(success: { [weak self] (prompt) in
344359
self?.prompt = prompt
345-
}, failure: { (error) in
360+
self?.didFailLoadingPrompt = false
361+
}, failure: { [weak self] (error) in
362+
self?.didFailLoadingPrompt = true
346363
DDLogError("Failed fetching blogging prompt: \(String(describing: error))")
347364
})
348365
}
@@ -412,6 +429,7 @@ private extension DashboardPromptsCardCell {
412429
+ "that answered the blogging prompt.")
413430
static let answerInfoPluralFormat = NSLocalizedString("%1$d answers", comment: "Plural format string for displaying the number of users "
414431
+ "that answered the blogging prompt.")
432+
static let errorTitle = NSLocalizedString("Error loading prompt", comment: "Text displayed when there is a failure loading a blogging prompt.")
415433
}
416434

417435
struct Style {

0 commit comments

Comments
 (0)