mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Present alert on macOS if using Edit > Delete as confirmation
This commit is contained in:
parent
3b4f50c601
commit
5af1d38a2d
@ -12,7 +12,8 @@ class WriteFreelyModel: ObservableObject {
|
|||||||
@Published var isLoggingIn: Bool = false
|
@Published var isLoggingIn: Bool = false
|
||||||
@Published var hasNetworkConnection: Bool = false
|
@Published var hasNetworkConnection: Bool = false
|
||||||
@Published var selectedPost: WFAPost?
|
@Published var selectedPost: WFAPost?
|
||||||
|
@Published var isPresentingDeleteAlert: Bool = false
|
||||||
|
@Published var postToDelete: WFAPost?
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
@Published var isPresentingSettingsView: Bool = false
|
@Published var isPresentingSettingsView: Bool = false
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,6 +13,24 @@ struct ContentView: View {
|
|||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
.environmentObject(model)
|
.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
|
||||||
|
withAnimation {
|
||||||
|
model.posts.remove(postToDelete)
|
||||||
|
}
|
||||||
|
model.postToDelete = nil
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
secondaryButton: .cancel() {
|
||||||
|
model.postToDelete = nil
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
EmptyView()
|
EmptyView()
|
||||||
|
@ -70,16 +70,15 @@ struct PostListFilteredView: View {
|
|||||||
.onDeleteCommand(perform: {
|
.onDeleteCommand(perform: {
|
||||||
guard let selectedPost = model.selectedPost else { return }
|
guard let selectedPost = model.selectedPost else { return }
|
||||||
if selectedPost.status == PostStatus.local.rawValue {
|
if selectedPost.status == PostStatus.local.rawValue {
|
||||||
delete(selectedPost)
|
model.postToDelete = selectedPost
|
||||||
|
model.isPresentingDeleteAlert = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
func delete(_ post: WFAPost) {
|
func delete(_ post: WFAPost) {
|
||||||
withAnimation {
|
model.posts.remove(post)
|
||||||
model.posts.remove(post)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
|
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>0</integer>
|
<integer>1</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
|
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>1</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
Loading…
Reference in New Issue
Block a user