Skip to content

Commit cb01548

Browse files
committed
Make RawBlockEditorSettingsService accept RawBlockEditorSettingsService as non-optional
1 parent 3daf9f0 commit cb01548

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

WordPress/Classes/Services/RawBlockEditorSettingsService.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ final class RawBlockEditorSettingsService {
77

88
private let blogID: String
99
private var refreshTask: Task<Data, Error>?
10-
private let dotOrgRestAPI: WordPressOrgRestApi?
10+
private let dotOrgRestAPI: WordPressOrgRestApi
1111
private var prefetchTask: Task<Void, Never>?
1212

1313
@MainActor
14-
init(blog: Blog) {
15-
self.dotOrgRestAPI = WordPressOrgRestApi(blog: blog)
14+
init(dotOrgRestAPI: WordPressOrgRestApi, blog: Blog) {
15+
self.dotOrgRestAPI = dotOrgRestAPI
1616
self.blogID = blog.locallyUniqueID
1717
}
1818

1919
private func fetchSettingsFromAPI() async throws -> Data {
20-
guard let dotOrgRestAPI else {
21-
throw URLError(.unknown)
22-
}
2320
let response: WordPressAPIResult<Data, WordPressOrgRestApiError> = await dotOrgRestAPI.get(
2421
path: "/wp-block-editor/v1/settings"
2522
)

WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ final class MySiteViewController: UIViewController, UIScrollViewDelegate, NoSite
358358
let configuration = EditorConfiguration(blog: blog)
359359
GutenbergKit.EditorViewController.warmup(configuration: configuration)
360360

361-
RawBlockEditorSettingsService(blog: blog).prefetchSettings()
361+
if let dotOrgRestAPI = WordPressOrgRestApi(blog: blog) {
362+
RawBlockEditorSettingsService(dotOrgRestAPI: dotOrgRestAPI, blog: blog)
363+
.prefetchSettings()
364+
}
362365
}
363366

364367
// MARK: - Main Blog

WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
145145
func setHTML(_ html: String) {}
146146
func getHTML() -> String { post.content ?? "" }
147147

148-
private let blockEditorSettingsService: RawBlockEditorSettingsService
148+
private let blockEditorSettingsService: RawBlockEditorSettingsService?
149149

150150
// MARK: - Initializers
151151
required convenience init(
@@ -183,7 +183,11 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
183183
let editorConfiguration = EditorConfiguration(blog: post.blog)
184184
self.editorViewController = GutenbergKit.EditorViewController(configuration: editorConfiguration)
185185

186-
self.blockEditorSettingsService = RawBlockEditorSettingsService(blog: post.blog)
186+
if let dotOrgRestAPI = WordPressOrgRestApi(blog: post.blog) {
187+
self.blockEditorSettingsService = RawBlockEditorSettingsService(dotOrgRestAPI: dotOrgRestAPI, blog: post.blog)
188+
} else {
189+
self.blockEditorSettingsService = nil
190+
}
187191

188192
super.init(nibName: nil, bundle: nil)
189193

@@ -474,12 +478,13 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
474478

475479
// MARK: - Editor Setup
476480
private func fetchEditorDependencies() async throws -> EditorDependencies {
477-
let settings: String?
478-
do {
479-
settings = try await blockEditorSettingsService.getSettingsString(allowingCachedResponse: true)
480-
} catch {
481-
DDLogError("Failed to fetch editor settings: \(error)")
482-
settings = nil
481+
var settings: String?
482+
if let blockEditorSettingsService {
483+
do {
484+
settings = try await blockEditorSettingsService.getSettingsString(allowingCachedResponse: true)
485+
} catch {
486+
DDLogError("Failed to fetch editor settings: \(error)")
487+
}
483488
}
484489

485490
let loaded = await loadAuthenticationCookiesAsync()

0 commit comments

Comments
 (0)