Skip to content

Commit 262aaaa

Browse files
committed
Merge branch 'alert-on-error-ios-code'
2 parents cf78484 + a315b09 commit 262aaaa

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

ActionExtension-iOS/ContentView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ struct ContentView: View {
160160
}
161161

162162
itemProvider.loadItem(forTypeIdentifier: typeIdentifier) { (dict, error) in
163-
if let error = error {
164-
print("⚠️", error)
163+
if error != nil {
165164
self.isShowingAlert = true
166165
}
167166

Shared/Models/WriteFreelyModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ final class WriteFreelyModel: ObservableObject {
1717
@Published var hasError: Bool = false
1818
var currentError: Error? {
1919
didSet {
20+
// TODO: Remove print statements for debugging before closing #204.
2021
#if DEBUG
2122
print("⚠️ currentError -> didSet \(currentError?.localizedDescription ?? "nil")")
2223
print(" > hasError was: \(self.hasError)")

iOS/PostEditor/PostEditorView.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SwiftUI
22

33
struct PostEditorView: View {
44
@EnvironmentObject var model: WriteFreelyModel
5+
@EnvironmentObject var errorHandling: ErrorHandling
56
@Environment(\.horizontalSizeClass) var horizontalSizeClass
67
@Environment(\.managedObjectContext) var moc
78
@Environment(\.presentationMode) var presentationMode
@@ -40,6 +41,7 @@ struct PostEditorView: View {
4041
updatingTitleFromServer: $updatingTitleFromServer,
4142
updatingBodyFromServer: $updatingBodyFromServer
4243
)
44+
.withErrorHandling()
4345
}
4446
.navigationBarTitleDisplayMode(.inline)
4547
.padding()
@@ -101,11 +103,6 @@ struct PostEditorView: View {
101103
})
102104
.accessibilityHint(Text("Open the system share sheet to share a link to this post"))
103105
.disabled(post.postId == nil)
104-
// Button(action: {
105-
// print("Tapped 'Delete...' button")
106-
// }, label: {
107-
// Label("Delete…", systemImage: "trash")
108-
// })
109106
if model.account.isLoggedIn && post.status != PostStatus.local.rawValue {
110107
Section(header: Text("Move To Collection")) {
111108
Label("Move to:", systemImage: "arrowshape.zigzag.right")
@@ -171,6 +168,16 @@ struct PostEditorView: View {
171168
self.model.editor.clearLastDraft()
172169
}
173170
})
171+
.onChange(of: model.hasError) { value in
172+
if value {
173+
if let error = model.currentError {
174+
self.errorHandling.handle(error: error)
175+
} else {
176+
self.errorHandling.handle(error: AppError.genericError())
177+
}
178+
model.hasError = false
179+
}
180+
}
174181
.onDisappear(perform: {
175182
self.model.editor.clearLastDraft()
176183
if post.title.count == 0

0 commit comments

Comments
 (0)