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