From 7863c2ba084332a9bae6b3a3a6008e83bd11638f Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Sat, 28 May 2022 09:23:16 -0400 Subject: [PATCH 1/2] Add error handling to post editor --- iOS/PostEditor/PostEditorView.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/iOS/PostEditor/PostEditorView.swift b/iOS/PostEditor/PostEditorView.swift index 7a78ad6..4fed230 100644 --- a/iOS/PostEditor/PostEditorView.swift +++ b/iOS/PostEditor/PostEditorView.swift @@ -2,6 +2,7 @@ import SwiftUI struct PostEditorView: View { @EnvironmentObject var model: WriteFreelyModel + @EnvironmentObject var errorHandling: ErrorHandling @Environment(\.horizontalSizeClass) var horizontalSizeClass @Environment(\.managedObjectContext) var moc @Environment(\.presentationMode) var presentationMode @@ -40,6 +41,7 @@ struct PostEditorView: View { updatingTitleFromServer: $updatingTitleFromServer, updatingBodyFromServer: $updatingBodyFromServer ) + .withErrorHandling() } .navigationBarTitleDisplayMode(.inline) .padding() @@ -101,11 +103,6 @@ struct PostEditorView: View { }) .accessibilityHint(Text("Open the system share sheet to share a link to this post")) .disabled(post.postId == nil) -// Button(action: { -// print("Tapped 'Delete...' button") -// }, label: { -// Label("Delete…", systemImage: "trash") -// }) if model.account.isLoggedIn && post.status != PostStatus.local.rawValue { Section(header: Text("Move To Collection")) { Label("Move to:", systemImage: "arrowshape.zigzag.right") @@ -171,6 +168,16 @@ struct PostEditorView: View { self.model.editor.clearLastDraft() } }) + .onChange(of: model.hasError) { value in + if value { + if let error = model.currentError { + self.errorHandling.handle(error: error) + } else { + self.errorHandling.handle(error: AppError.genericError()) + } + model.hasError = false + } + } .onDisappear(perform: { self.model.editor.clearLastDraft() if post.title.count == 0 From a315b0955351e326d1244205e6d879750c1c7543 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Tue, 31 May 2022 06:51:40 -0400 Subject: [PATCH 2/2] Cleanup --- ActionExtension-iOS/ContentView.swift | 3 +-- Shared/Models/WriteFreelyModel.swift | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ActionExtension-iOS/ContentView.swift b/ActionExtension-iOS/ContentView.swift index 0d38361..3e7b0d6 100644 --- a/ActionExtension-iOS/ContentView.swift +++ b/ActionExtension-iOS/ContentView.swift @@ -160,8 +160,7 @@ struct ContentView: View { } itemProvider.loadItem(forTypeIdentifier: typeIdentifier) { (dict, error) in - if let error = error { - print("⚠️", error) + if error != nil { self.isShowingAlert = true } diff --git a/Shared/Models/WriteFreelyModel.swift b/Shared/Models/WriteFreelyModel.swift index 617385f..ba778d0 100644 --- a/Shared/Models/WriteFreelyModel.swift +++ b/Shared/Models/WriteFreelyModel.swift @@ -17,6 +17,7 @@ final class WriteFreelyModel: ObservableObject { @Published var hasError: Bool = false var currentError: Error? { didSet { + // TODO: Remove print statements for debugging before closing #204. #if DEBUG print("⚠️ currentError -> didSet \(currentError?.localizedDescription ?? "nil")") print(" > hasError was: \(self.hasError)")