Add button to remove a tag
This commit is contained in:
parent
a8920a4cd2
commit
a4710d525b
@ -29,6 +29,12 @@ final class SelectedContent: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func remove(_ tag: Tag) {
|
||||
if self.tag == tag {
|
||||
self.tag = nil
|
||||
}
|
||||
}
|
||||
|
||||
func remove(_ file: FileResource) {
|
||||
if self.file == file {
|
||||
self.file = nil
|
||||
|
@ -145,6 +145,17 @@ final class Content: ObservableObject {
|
||||
// TODO: Check for page links and other references in content
|
||||
}
|
||||
|
||||
func remove(_ tag: Tag) {
|
||||
tags.remove(tag)
|
||||
for post in posts {
|
||||
post.tags.remove(tag)
|
||||
}
|
||||
for page in pages {
|
||||
page.tags.remove(tag)
|
||||
}
|
||||
// TODO: Check for tag links and other references is content
|
||||
}
|
||||
|
||||
// MARK: Loading
|
||||
|
||||
func file(withOutputPath: String) -> FileResource? {
|
||||
|
@ -151,9 +151,7 @@ final class Storage: ObservableObject {
|
||||
Completely delete a post file from the content folder
|
||||
*/
|
||||
func delete(page pageId: String) -> Bool {
|
||||
guard let contentScope else {
|
||||
return false
|
||||
}
|
||||
guard let contentScope else { return false }
|
||||
guard contentScope.deleteFile(at: pageMetadataPath(page: pageId)) else {
|
||||
return false
|
||||
}
|
||||
@ -213,9 +211,7 @@ final class Storage: ObservableObject {
|
||||
Completely delete a post file from the content folder
|
||||
*/
|
||||
func delete(post postId: String) -> Bool {
|
||||
guard let contentScope else {
|
||||
return false
|
||||
}
|
||||
guard let contentScope else { return false }
|
||||
return contentScope.deleteFile(at: postFilePath(post: postId))
|
||||
}
|
||||
|
||||
@ -258,6 +254,11 @@ final class Storage: ObservableObject {
|
||||
return contentScope.move(tagFilePath(tag: tagId), to: tagFilePath(tag: newId))
|
||||
}
|
||||
|
||||
func delete(tag tagId: String) -> Bool {
|
||||
guard let contentScope else { return false }
|
||||
return contentScope.deleteFile(at: tagFilePath(tag: tagId))
|
||||
}
|
||||
|
||||
// MARK: Files
|
||||
|
||||
func size(of file: String) -> Int? {
|
||||
|
@ -6,6 +6,12 @@ struct TagDetailView: View {
|
||||
@Environment(\.language)
|
||||
private var language
|
||||
|
||||
@EnvironmentObject
|
||||
private var content: Content
|
||||
|
||||
@EnvironmentObject
|
||||
private var selection: SelectedContent
|
||||
|
||||
@ObservedObject
|
||||
var tag: Tag
|
||||
|
||||
@ -37,10 +43,20 @@ struct TagDetailView: View {
|
||||
tag: tag.localized(in: language),
|
||||
transferImage: transferImage)
|
||||
.id(tag.id + language.rawValue)
|
||||
DeleteButton(action: deleteTag)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
private func deleteTag() {
|
||||
guard content.storage.delete(tag: tag.id) else {
|
||||
print("Tag '\(tag.id)': Failed to delete file in content folder")
|
||||
return
|
||||
}
|
||||
content.remove(tag)
|
||||
selection.remove(tag)
|
||||
}
|
||||
}
|
||||
|
||||
extension TagDetailView: MainContentView {
|
||||
|
Loading…
x
Reference in New Issue
Block a user