Add button to remove post
This commit is contained in:
@ -16,4 +16,10 @@ final class SelectedContent: ObservableObject {
|
||||
|
||||
@Published
|
||||
var file: FileResource?
|
||||
|
||||
func remove(_ post: Post) {
|
||||
if self.post == post {
|
||||
self.post = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,8 @@ final class Content: ObservableObject {
|
||||
loadFromDisk(callback: callback)
|
||||
}
|
||||
|
||||
// MARK: Removing items
|
||||
|
||||
func remove(_ file: FileResource) {
|
||||
files.remove(file)
|
||||
for post in posts {
|
||||
@ -129,6 +131,10 @@ final class Content: ObservableObject {
|
||||
settings.remove(file)
|
||||
}
|
||||
|
||||
func remove(_ post: Post) {
|
||||
posts.remove(post)
|
||||
}
|
||||
|
||||
func file(withOutputPath: String) -> FileResource? {
|
||||
files.first { $0.absoluteUrl == withOutputPath }
|
||||
}
|
||||
|
@ -186,6 +186,16 @@ final class Storage: ObservableObject {
|
||||
return contentScope.move(postFilePath(post: postId), to: postFilePath(post: newId))
|
||||
}
|
||||
|
||||
/**
|
||||
Completely delete a post file from the content folder
|
||||
*/
|
||||
func delete(post postId: String) -> Bool {
|
||||
guard let contentScope else {
|
||||
return false
|
||||
}
|
||||
return contentScope.deleteFile(at: postFilePath(post: postId))
|
||||
}
|
||||
|
||||
// MARK: Tags
|
||||
|
||||
private func tagFileName(tagId: String) -> String {
|
||||
|
20
CHDataManagement/Views/Generic/DeleteButton.swift
Normal file
20
CHDataManagement/Views/Generic/DeleteButton.swift
Normal 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)
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user