diff --git a/Shared/Models/WriteFreelyModel.swift b/Shared/Models/WriteFreelyModel.swift index 59835f8..5923939 100644 --- a/Shared/Models/WriteFreelyModel.swift +++ b/Shared/Models/WriteFreelyModel.swift @@ -12,7 +12,8 @@ class WriteFreelyModel: ObservableObject { @Published var isLoggingIn: Bool = false @Published var hasNetworkConnection: Bool = false @Published var selectedPost: WFAPost? - + @Published var isPresentingDeleteAlert: Bool = false + @Published var postToDelete: WFAPost? #if os(iOS) @Published var isPresentingSettingsView: Bool = false #endif diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index 8cbefca..732b187 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -13,6 +13,24 @@ 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 + withAnimation { + model.posts.remove(postToDelete) + } + model.postToDelete = nil + } + }), + secondaryButton: .cancel() { + model.postToDelete = nil + } + ) + } #if os(iOS) EmptyView() diff --git a/Shared/PostList/PostListFilteredView.swift b/Shared/PostList/PostListFilteredView.swift index 84b8c3b..9f72c94 100644 --- a/Shared/PostList/PostListFilteredView.swift +++ b/Shared/PostList/PostListFilteredView.swift @@ -70,16 +70,15 @@ struct PostListFilteredView: View { .onDeleteCommand(perform: { guard let selectedPost = model.selectedPost else { return } if selectedPost.status == PostStatus.local.rawValue { - delete(selectedPost) + model.postToDelete = selectedPost + model.isPresentingDeleteAlert = true } }) #endif } func delete(_ post: WFAPost) { - withAnimation { - model.posts.remove(post) - } + model.posts.remove(post) } } diff --git a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist index 2723ebe..6cd8075 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_ orderHint - 0 + 1 WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_ orderHint - 1 + 0