Skip to content

Commit a7cfceb

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

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
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: 14 additions & 7 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,12 @@ 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: blog) {
187+
self.blockEditorSettingsService = RawBlockEditorSettingsService(dotOrgRestAPI: dotOrgRestAPI, blog: blog)
188+
.prefetchSettings()
189+
} else {
190+
self.blockEditorSettingsService = nil
191+
}
187192

188193
super.init(nibName: nil, bundle: nil)
189194

@@ -475,11 +480,13 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
475480
// MARK: - Editor Setup
476481
private func fetchEditorDependencies() async throws -> EditorDependencies {
477482
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
483+
if let blockEditorSettingsService {
484+
do {
485+
settings = try await blockEditorSettingsService.getSettingsString(allowingCachedResponse: true)
486+
} catch {
487+
DDLogError("Failed to fetch editor settings: \(error)")
488+
settings = nil
489+
}
483490
}
484491

485492
let loaded = await loadAuthenticationCookiesAsync()

0 commit comments

Comments
 (0)