@@ -35,6 +35,10 @@ class BloggingPromptsIntroductionPresenter: NSObject {
35
35
( accountSites? . count ?? 0 ) == 0
36
36
} ( )
37
37
38
+ private lazy var bloggingPromptsService : BloggingPromptsService ? = {
39
+ return BloggingPromptsService ( blog: blogToUse ( ) )
40
+ } ( )
41
+
38
42
// MARK: - Present Feature Introduction
39
43
40
44
func present( from presentingViewController: UIViewController ) {
@@ -103,15 +107,21 @@ private extension BloggingPromptsIntroductionPresenter {
103
107
return
104
108
}
105
109
106
- // TODO: pre-populate post content with prompt from backend instead
107
- // of example prompt
108
- let editor = EditPostViewController ( blog: blog, prompt: . examplePrompt)
109
- editor. modalPresentationStyle = . fullScreen
110
- editor. entryPoint = . bloggingPromptsFeatureIntroduction
111
-
112
- navigationController. dismiss ( animated: true , completion: { [ weak self] in
113
- presentingViewController. present ( editor, animated: false )
114
- self ? . trackPostEditorShown ( blog)
110
+ fetchPrompt ( completion: { [ weak self] ( prompt) in
111
+ guard let prompt = prompt else {
112
+ self ? . dispatchErrorNotice ( )
113
+ self ? . navigationController. dismiss ( animated: true )
114
+ return
115
+ }
116
+
117
+ let editor = EditPostViewController ( blog: blog, prompt: prompt)
118
+ editor. modalPresentationStyle = . fullScreen
119
+ editor. entryPoint = . bloggingPromptsFeatureIntroduction
120
+
121
+ self ? . navigationController. dismiss ( animated: true , completion: { [ weak self] in
122
+ presentingViewController. present ( editor, animated: false )
123
+ self ? . trackPostEditorShown ( blog)
124
+ } )
115
125
} )
116
126
}
117
127
@@ -139,4 +149,27 @@ private extension BloggingPromptsIntroductionPresenter {
139
149
with: blog)
140
150
}
141
151
152
+ // MARK: Prompt Fetching
153
+
154
+ func fetchPrompt( completion: @escaping ( ( _ prompt: BloggingPrompt ? ) -> Void ) ) {
155
+ // TODO: check for cached prompt first.
156
+
157
+ guard let bloggingPromptsService = bloggingPromptsService else {
158
+ DDLogError ( " Feature Introduction: failed creating BloggingPromptsService instance. " )
159
+ return
160
+ }
161
+
162
+ bloggingPromptsService. fetchTodaysPrompt ( success: { ( prompt) in
163
+ completion ( prompt)
164
+ } , failure: { ( error) in
165
+ completion ( nil )
166
+ DDLogError ( " Feature Introduction: failed fetching blogging prompt: \( String ( describing: error) ) " )
167
+ } )
168
+ }
169
+
170
+ func dispatchErrorNotice( ) {
171
+ let message = NSLocalizedString ( " Error loading prompt " , comment: " Text displayed when there is a failure loading a blogging prompt. " )
172
+ presentingViewController? . displayNotice ( title: message)
173
+ }
174
+
142
175
}
0 commit comments