Restore alerts on Edit > Delete, no-network failure

This commit is contained in:
Angelo Stavrow 2020-11-26 16:38:39 -05:00
parent b788994144
commit 5dabe97db4
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 39 additions and 27 deletions

View File

@ -65,6 +65,17 @@ struct ContentView: View {
.disabled(!model.account.isLoggedIn)
.padding(.leading, sidebarIsHidden ? 8 : 0)
.animation(.linear)
.alert(isPresented: $model.isPresentingNetworkErrorAlert, content: {
Alert(
title: Text("Connection Error"),
message: Text("""
There is no internet connection at the moment. Please reconnect or try again later.
"""),
dismissButton: .default(Text("OK"), action: {
model.isPresentingNetworkErrorAlert = false
})
)
})
}
ToolbarItem(placement: .status) {
if let selectedPost = model.selectedPost {
@ -93,33 +104,6 @@ struct ContentView: View {
.foregroundColor(.secondary)
}
.environmentObject(model)
.alert(isPresented: $model.isPresentingDeleteAlert) {
Alert(
title: Text("Delete Post?"),
message: Text("This action cannot be undone."),
primaryButton: .destructive(Text("Delete"), action: {
if let postToDelete = model.postToDelete {
model.selectedPost = nil
DispatchQueue.main.async {
model.posts.remove(postToDelete)
}
model.postToDelete = nil
}
}),
secondaryButton: .cancel() {
model.postToDelete = nil
}
)
}
.alert(isPresented: $model.isPresentingNetworkErrorAlert, content: {
Alert(
title: Text("Connection Error"),
message: Text("There is no internet connection at the moment. Please reconnect or try again later"),
dismissButton: .default(Text("OK"), action: {
model.isPresentingNetworkErrorAlert = false
})
)
})
#if os(iOS)
EmptyView()
@ -131,6 +115,15 @@ struct ContentView: View {
.environmentObject(model)
}
)
.alert(isPresented: $model.isPresentingNetworkErrorAlert, content: {
Alert(
title: Text("Connection Error"),
message: Text("There is no internet connection at the moment. Please reconnect or try again later."),
dismissButton: .default(Text("OK"), action: {
model.isPresentingNetworkErrorAlert = false
})
)
})
#endif
}
}

View File

@ -86,6 +86,24 @@ struct PostListFilteredView: View {
}
})
}
.alert(isPresented: $model.isPresentingDeleteAlert) {
Alert(
title: Text("Delete Post?"),
message: Text("This action cannot be undone."),
primaryButton: .destructive(Text("Delete"), action: {
if let postToDelete = model.postToDelete {
model.selectedPost = nil
DispatchQueue.main.async {
model.posts.remove(postToDelete)
}
model.postToDelete = nil
}
}),
secondaryButton: .cancel() {
model.postToDelete = nil
}
)
}
.onAppear(perform: {
self.postCount = fetchRequest.wrappedValue.count
})
@ -104,6 +122,7 @@ struct PostListFilteredView: View {
func delete(_ post: WFAPost) {
DispatchQueue.main.async {
model.selectedPost = nil
model.posts.remove(post)
}
}