Skip to content

Commit c536706

Browse files
committed
Fix cache read preventing the download from happening
1 parent fe45f0e commit c536706

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
@@ -181,10 +181,7 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
181181
// DDLogError("Error syncing JETPACK: \(String(describing: error))")
182182
// })
183183

184-
editorLoadingTask = Task { @MainActor in
185-
await loadEditor()
186-
}
187-
184+
loadEditor()
188185
onViewDidLoad()
189186
}
190187

@@ -212,7 +209,7 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
212209
setContentScrollView(editorViewController.webView.scrollView)
213210
}
214211

215-
// MARK: - Functions
212+
// MARK: - Helpers
216213

217214
private func configureNavigationBar() {
218215
navigationController?.navigationBar.accessibilityIdentifier = "Gutenberg Editor Navigation Bar"
@@ -277,29 +274,6 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
277274
}
278275
}
279276

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

305279
private func setupKeyboardObservers() {
@@ -367,6 +341,45 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
367341
}
368342

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

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

0 commit comments

Comments
 (0)