Skip to content

Commit 8c4b3ca

Browse files
authored
Merge pull request #18597 from wordpress-mobile/feature/18429-fi_try_it_prompt
Blogging Prompts Feature Introduction: use real prompt for new post
2 parents 436f005 + 82f8c5c commit 8c4b3ca

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

WordPress/Classes/ViewRelated/Feature Introduction/Blogging Prompts/BloggingPromptsIntroductionPresenter.swift

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class BloggingPromptsIntroductionPresenter: NSObject {
3535
(accountSites?.count ?? 0) == 0
3636
}()
3737

38+
private lazy var bloggingPromptsService: BloggingPromptsService? = {
39+
return BloggingPromptsService(blog: blogToUse())
40+
}()
41+
3842
// MARK: - Present Feature Introduction
3943

4044
func present(from presentingViewController: UIViewController) {
@@ -103,15 +107,21 @@ private extension BloggingPromptsIntroductionPresenter {
103107
return
104108
}
105109

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+
})
115125
})
116126
}
117127

@@ -139,4 +149,27 @@ private extension BloggingPromptsIntroductionPresenter {
139149
with: blog)
140150
}
141151

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+
142175
}

0 commit comments

Comments
 (0)