@@ -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