mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add Edit > Delete menu command on macOS
This commit is contained in:
parent
77262c9cd6
commit
3b4f50c601
@ -29,6 +29,7 @@ struct PostListFilteredView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
#if os(iOS)
|
||||
List {
|
||||
ForEach(fetchRequest.wrappedValue, id: \.self) { post in
|
||||
NavigationLink(
|
||||
@ -47,10 +48,38 @@ struct PostListFilteredView: View {
|
||||
}
|
||||
})
|
||||
}
|
||||
#else
|
||||
List {
|
||||
ForEach(fetchRequest.wrappedValue, id: \.self) { post in
|
||||
NavigationLink(
|
||||
destination: PostEditorView(post: post),
|
||||
tag: post,
|
||||
selection: $model.selectedPost
|
||||
) {
|
||||
PostCellView(post: post)
|
||||
}
|
||||
.deleteDisabled(post.status != PostStatus.local.rawValue)
|
||||
}
|
||||
.onDelete(perform: { indexSet in
|
||||
for index in indexSet {
|
||||
let post = fetchRequest.wrappedValue[index]
|
||||
delete(post)
|
||||
}
|
||||
})
|
||||
}
|
||||
.onDeleteCommand(perform: {
|
||||
guard let selectedPost = model.selectedPost else { return }
|
||||
if selectedPost.status == PostStatus.local.rawValue {
|
||||
delete(selectedPost)
|
||||
}
|
||||
})
|
||||
#endif
|
||||
}
|
||||
|
||||
func delete(_ post: WFAPost) {
|
||||
model.posts.remove(post)
|
||||
withAnimation {
|
||||
model.posts.remove(post)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user