Add button to remove post

This commit is contained in:
Christoph Hagen
2025-05-04 11:48:09 +02:00
parent d6502fb09c
commit 329519e15b
6 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import SwiftUI
struct DeleteButton: View {
let action: () -> Void
var body: some View {
Button(action: action) {
HStack {
Spacer()
Image(systemSymbol: .trash)
Text("Delete")
.padding(.vertical, 8)
Spacer()
}
.foregroundStyle(Color.white)
.background(RoundedRectangle(cornerRadius: 8).fill(Color.red))
}.buttonStyle(.plain)
}
}

View File

@ -76,6 +76,7 @@ struct PostDetailView: View {
LocalizedPostDetailView(
post: post.localized(in: language),
transferImage: transferImage)
DeleteButton(action: deletePost)
}
.padding()
}
@ -90,6 +91,15 @@ struct PostDetailView: View {
selection.tab = .pages
}
}
private func deletePost() {
guard content.storage.delete(post: post.id) else {
print("Post '\(post.id)': Failed to delete file in content folder")
return
}
content.remove(post)
selection.remove(post)
}
}
extension PostDetailView: MainContentView {