Add button to remove post
This commit is contained in:
parent
d6502fb09c
commit
329519e15b
@ -207,6 +207,7 @@
|
|||||||
E2F3B3982DC54F9400CFA712 /* ChangeObservingItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F3B3972DC54F8600CFA712 /* ChangeObservingItem.swift */; };
|
E2F3B3982DC54F9400CFA712 /* ChangeObservingItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F3B3972DC54F8600CFA712 /* ChangeObservingItem.swift */; };
|
||||||
E2F3B39C2DC5542E00CFA712 /* LabelEditingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F3B39B2DC5542E00CFA712 /* LabelEditingView.swift */; };
|
E2F3B39C2DC5542E00CFA712 /* LabelEditingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F3B39B2DC5542E00CFA712 /* LabelEditingView.swift */; };
|
||||||
E2F3B39E2DC55B1C00CFA712 /* LabelCreationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F3B39D2DC55B1C00CFA712 /* LabelCreationView.swift */; };
|
E2F3B39E2DC55B1C00CFA712 /* LabelCreationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F3B39D2DC55B1C00CFA712 /* LabelCreationView.swift */; };
|
||||||
|
E2F3B3A22DC769C300CFA712 /* DeleteButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F3B3A12DC769BF00CFA712 /* DeleteButton.swift */; };
|
||||||
E2FD1D0D2D2DBBA600B48627 /* LinkPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D0C2D2DBBA100B48627 /* LinkPreview.swift */; };
|
E2FD1D0D2D2DBBA600B48627 /* LinkPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D0C2D2DBBA100B48627 /* LinkPreview.swift */; };
|
||||||
E2FD1D192D2DC4F500B48627 /* LoadingContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D182D2DC4F500B48627 /* LoadingContext.swift */; };
|
E2FD1D192D2DC4F500B48627 /* LoadingContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D182D2DC4F500B48627 /* LoadingContext.swift */; };
|
||||||
E2FD1D1B2D2DC63800B48627 /* LinkPreviewDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D1A2D2DC62C00B48627 /* LinkPreviewDetailView.swift */; };
|
E2FD1D1B2D2DC63800B48627 /* LinkPreviewDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D1A2D2DC62C00B48627 /* LinkPreviewDetailView.swift */; };
|
||||||
@ -490,6 +491,7 @@
|
|||||||
E2F3B3972DC54F8600CFA712 /* ChangeObservingItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeObservingItem.swift; sourceTree = "<group>"; };
|
E2F3B3972DC54F8600CFA712 /* ChangeObservingItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeObservingItem.swift; sourceTree = "<group>"; };
|
||||||
E2F3B39B2DC5542E00CFA712 /* LabelEditingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelEditingView.swift; sourceTree = "<group>"; };
|
E2F3B39B2DC5542E00CFA712 /* LabelEditingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelEditingView.swift; sourceTree = "<group>"; };
|
||||||
E2F3B39D2DC55B1C00CFA712 /* LabelCreationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelCreationView.swift; sourceTree = "<group>"; };
|
E2F3B39D2DC55B1C00CFA712 /* LabelCreationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelCreationView.swift; sourceTree = "<group>"; };
|
||||||
|
E2F3B3A12DC769BF00CFA712 /* DeleteButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteButton.swift; sourceTree = "<group>"; };
|
||||||
E2FD1D0C2D2DBBA100B48627 /* LinkPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreview.swift; sourceTree = "<group>"; };
|
E2FD1D0C2D2DBBA100B48627 /* LinkPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreview.swift; sourceTree = "<group>"; };
|
||||||
E2FD1D182D2DC4F500B48627 /* LoadingContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingContext.swift; sourceTree = "<group>"; };
|
E2FD1D182D2DC4F500B48627 /* LoadingContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingContext.swift; sourceTree = "<group>"; };
|
||||||
E2FD1D1A2D2DC62C00B48627 /* LinkPreviewDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewDetailView.swift; sourceTree = "<group>"; };
|
E2FD1D1A2D2DC62C00B48627 /* LinkPreviewDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewDetailView.swift; sourceTree = "<group>"; };
|
||||||
@ -829,6 +831,7 @@
|
|||||||
E2A21C372CB9A4F10060935B /* Generic */ = {
|
E2A21C372CB9A4F10060935B /* Generic */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
E2F3B3A12DC769BF00CFA712 /* DeleteButton.swift */,
|
||||||
E229902F2D0F75CF009F8D77 /* BoolPropertyView.swift */,
|
E229902F2D0F75CF009F8D77 /* BoolPropertyView.swift */,
|
||||||
E22990312D0F7678009F8D77 /* DatePropertyView.swift */,
|
E22990312D0F7678009F8D77 /* DatePropertyView.swift */,
|
||||||
E29D312F2D03A2BD0051B7F4 /* DescriptionField.swift */,
|
E29D312F2D03A2BD0051B7F4 /* DescriptionField.swift */,
|
||||||
@ -1449,6 +1452,7 @@
|
|||||||
E25DA58B2D020C9500AEF16D /* PageImage.swift in Sources */,
|
E25DA58B2D020C9500AEF16D /* PageImage.swift in Sources */,
|
||||||
E2521DFC2D5020BE00C56662 /* PostContentGenerator.swift in Sources */,
|
E2521DFC2D5020BE00C56662 /* PostContentGenerator.swift in Sources */,
|
||||||
E21850232CF10C850090B18B /* TagSelectionView.swift in Sources */,
|
E21850232CF10C850090B18B /* TagSelectionView.swift in Sources */,
|
||||||
|
E2F3B3A22DC769C300CFA712 /* DeleteButton.swift in Sources */,
|
||||||
E2A21C332CB5BCAC0060935B /* PageContentView.swift in Sources */,
|
E2A21C332CB5BCAC0060935B /* PageContentView.swift in Sources */,
|
||||||
E22990402D0F95EC009F8D77 /* FolderOnDiskPropertyView.swift in Sources */,
|
E22990402D0F95EC009F8D77 /* FolderOnDiskPropertyView.swift in Sources */,
|
||||||
E2FE0F422D2B4821002963B7 /* OtherCodeBlock.swift in Sources */,
|
E2FE0F422D2B4821002963B7 /* OtherCodeBlock.swift in Sources */,
|
||||||
|
@ -16,4 +16,10 @@ final class SelectedContent: ObservableObject {
|
|||||||
|
|
||||||
@Published
|
@Published
|
||||||
var file: FileResource?
|
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)
|
loadFromDisk(callback: callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Removing items
|
||||||
|
|
||||||
func remove(_ file: FileResource) {
|
func remove(_ file: FileResource) {
|
||||||
files.remove(file)
|
files.remove(file)
|
||||||
for post in posts {
|
for post in posts {
|
||||||
@ -129,6 +131,10 @@ final class Content: ObservableObject {
|
|||||||
settings.remove(file)
|
settings.remove(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func remove(_ post: Post) {
|
||||||
|
posts.remove(post)
|
||||||
|
}
|
||||||
|
|
||||||
func file(withOutputPath: String) -> FileResource? {
|
func file(withOutputPath: String) -> FileResource? {
|
||||||
files.first { $0.absoluteUrl == withOutputPath }
|
files.first { $0.absoluteUrl == withOutputPath }
|
||||||
}
|
}
|
||||||
|
@ -186,6 +186,16 @@ final class Storage: ObservableObject {
|
|||||||
return contentScope.move(postFilePath(post: postId), to: postFilePath(post: newId))
|
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
|
// MARK: Tags
|
||||||
|
|
||||||
private func tagFileName(tagId: String) -> String {
|
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(
|
LocalizedPostDetailView(
|
||||||
post: post.localized(in: language),
|
post: post.localized(in: language),
|
||||||
transferImage: transferImage)
|
transferImage: transferImage)
|
||||||
|
DeleteButton(action: deletePost)
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
@ -90,6 +91,15 @@ struct PostDetailView: View {
|
|||||||
selection.tab = .pages
|
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 {
|
extension PostDetailView: MainContentView {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user