@@ -65,6 +65,14 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
65
65
}
66
66
}
67
67
68
+ private var didFailLoadingPrompt : Bool = false {
69
+ didSet {
70
+ if didFailLoadingPrompt != oldValue {
71
+ refreshStackView ( )
72
+ }
73
+ }
74
+ }
75
+
68
76
// Used to present:
69
77
// - The menu sheet for contextual menu in iOS13.
70
78
// - The Blogging Prompts list when selected from the contextual menu.
@@ -320,6 +328,12 @@ private extension DashboardPromptsCardCell {
320
328
// clear existing views.
321
329
containerStackView. removeAllSubviews ( )
322
330
331
+ guard !didFailLoadingPrompt else {
332
+ promptLabel. text = Strings . errorTitle
333
+ containerStackView. addArrangedSubview ( promptTitleView)
334
+ return
335
+ }
336
+
323
337
promptLabel. text = forExampleDisplay ? Strings . examplePrompt : prompt? . text. stringByDecodingXMLCharacters ( ) . trim ( )
324
338
containerStackView. addArrangedSubview ( promptTitleView)
325
339
@@ -336,13 +350,16 @@ private extension DashboardPromptsCardCell {
336
350
// TODO: check for cached prompt first.
337
351
338
352
guard let bloggingPromptsService = bloggingPromptsService else {
353
+ didFailLoadingPrompt = true
339
354
DDLogError ( " Failed creating BloggingPromptsService instance. " )
340
355
return
341
356
}
342
357
343
358
bloggingPromptsService. fetchTodaysPrompt ( success: { [ weak self] ( prompt) in
344
359
self ? . prompt = prompt
345
- } , failure: { ( error) in
360
+ self ? . didFailLoadingPrompt = false
361
+ } , failure: { [ weak self] ( error) in
362
+ self ? . didFailLoadingPrompt = true
346
363
DDLogError ( " Failed fetching blogging prompt: \( String ( describing: error) ) " )
347
364
} )
348
365
}
@@ -412,6 +429,7 @@ private extension DashboardPromptsCardCell {
412
429
+ " that answered the blogging prompt. " )
413
430
static let answerInfoPluralFormat = NSLocalizedString ( " %1$d answers " , comment: " Plural format string for displaying the number of users "
414
431
+ " 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. " )
415
433
}
416
434
417
435
struct Style {
0 commit comments