Skip to content

Commit 91f54a4

Browse files
committed
Fix cache read preventing the download from happening
1 parent 38762ae commit 91f54a4

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

WordPress/Classes/Services/BlockEditorCache.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ final actor BlockEditorCache {
2424
try settings.write(to: fileURL)
2525
}
2626

27-
func getBlockSettings(for blogID: String) throws -> Data? {
27+
func getBlockSettings(for blogID: String) -> Data? {
2828
let fileURL = makeBlockSettingsURL(for: blogID)
29-
3029
guard FileManager.default.fileExists(atPath: fileURL.path) else {
3130
return nil
3231
}
33-
34-
return try Data(contentsOf: fileURL)
32+
return try? Data(contentsOf: fileURL)
3533
}
3634

3735
func deleteBlockSettings(for blogID: String) throws {

WordPress/Classes/Services/RawBlockEditorSettingsService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class RawBlockEditorSettingsService {
3131
/// the network.
3232
func getSettings(allowingCachedResponse: Bool = true) async throws -> Data {
3333
// Return cached settings if available
34-
if allowingCachedResponse, let cachedSettings = try await BlockEditorCache.shared.getBlockSettings(for: blogID) {
34+
if allowingCachedResponse, let cachedSettings = await BlockEditorCache.shared.getBlockSettings(for: blogID) {
3535
return cachedSettings
3636
}
3737
return try await fetchSettingsFromAPI()

WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
184184
// DDLogError("Error syncing JETPACK: \(String(describing: error))")
185185
// })
186186

187-
editorLoadingTask = Task { @MainActor in
188-
await loadEditor()
189-
}
190-
187+
loadEditor()
191188
onViewDidLoad()
192189
}
193190

@@ -215,7 +212,7 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
215212
setContentScrollView(editorViewController.webView.scrollView)
216213
}
217214

218-
// MARK: - Functions
215+
// MARK: - Helpers
219216

220217
private func configureNavigationBar() {
221218
navigationController?.navigationBar.accessibilityIdentifier = "Gutenberg Editor Navigation Bar"
@@ -280,29 +277,6 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
280277
}
281278
}
282279

283-
@MainActor
284-
private func loadEditor() async {
285-
showActivityIndicator()
286-
287-
do {
288-
let dependencies = try await fetchEditorDependencies()
289-
290-
let configuration = editorViewController.configuration.toBuilder()
291-
.apply(dependencies.settings) { $0.setEditorSettings($1) }
292-
.setTitle(post.postTitle ?? "")
293-
.setContent(post.content ?? "")
294-
.build()
295-
296-
editorViewController.updateConfiguration(configuration)
297-
editorViewController.startEditorSetup()
298-
299-
// Handles refreshing controls with state context after options screen is dismissed
300-
editorContentWasUpdated()
301-
} catch {
302-
// TODO: handle errors
303-
}
304-
}
305-
306280
// MARK: - Keyboard Observers
307281

308282
private func setupKeyboardObservers() {
@@ -370,6 +344,45 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
370344
}
371345

372346
// MARK: - Editor Setup
347+
348+
private func loadEditor() {
349+
editorLoadingTask = Task { @MainActor in
350+
await actuallyLoadEditor()
351+
}
352+
}
353+
354+
@MainActor
355+
private func actuallyLoadEditor() async {
356+
showActivityIndicator()
357+
358+
do {
359+
let dependencies = try await fetchEditorDependencies()
360+
startEditor(dependencies: dependencies)
361+
} catch {
362+
hideActivityIndicator()
363+
364+
let host = UIHostingView(view: EmptyStateView.failure(error: error) { [weak self] in
365+
self?.loadEditor()
366+
})
367+
view.addSubview(host)
368+
host.pinEdges()
369+
}
370+
}
371+
372+
private func startEditor(dependencies: EditorDependencies) {
373+
let configuration = editorViewController.configuration.toBuilder()
374+
.apply(dependencies.settings) { $0.setEditorSettings($1) }
375+
.setTitle(post.postTitle ?? "")
376+
.setContent(post.content ?? "")
377+
.build()
378+
379+
editorViewController.updateConfiguration(configuration)
380+
editorViewController.startEditorSetup()
381+
382+
// Handles refreshing controls with state context after options screen is dismissed
383+
editorContentWasUpdated()
384+
}
385+
373386
private func fetchEditorDependencies() async throws -> EditorDependencies {
374387
let settings: String?
375388
do {
@@ -424,7 +437,7 @@ extension NewGutenbergViewController: GutenbergKit.EditorViewControllerDelegate
424437
// is still reflecting the actual startup time of the editor
425438
editorSession.start()
426439
}
427-
self.hideActivityIndicator()
440+
hideActivityIndicator()
428441
}
429442

430443
func editor(_ viewContoller: GutenbergKit.EditorViewController, didDisplayInitialContent content: String) {

0 commit comments

Comments
 (0)