Better undelete handling

This commit is contained in:
Jackson Harper 2023-07-12 17:07:34 +08:00
parent 52776521f3
commit ec55801eff
2 changed files with 48 additions and 37 deletions

View file

@ -318,39 +318,46 @@ struct AnimatingCellHeight: AnimatableModifier {
func menuItems(for item: LinkedItem) -> some View {
Group {
Button(
action: { viewModel.itemUnderTitleEdit = item },
label: { Label("Edit Info", systemImage: "info.circle") }
)
Button(
action: { viewModel.itemUnderLabelEdit = item },
label: { Label(item.labels?.count == 0 ? "Add Labels" : "Edit Labels", systemImage: "tag") }
)
Button(action: {
withAnimation(.linear(duration: 0.4)) {
viewModel.setLinkArchived(
dataService: dataService,
objectID: item.objectID,
archived: !item.isArchived
if item.state != "DELETED" {
Button(
action: { viewModel.itemUnderTitleEdit = item },
label: { Label("Edit Info", systemImage: "info.circle") }
)
Button(
action: { viewModel.itemUnderLabelEdit = item },
label: { Label(item.labels?.count == 0 ? "Add Labels" : "Edit Labels", systemImage: "tag") }
)
Button(action: {
withAnimation(.linear(duration: 0.4)) {
viewModel.setLinkArchived(
dataService: dataService,
objectID: item.objectID,
archived: !item.isArchived
)
}
}, label: {
Label(
item.isArchived ? "Unarchive" : "Archive",
systemImage: item.isArchived ? "tray.and.arrow.down.fill" : "archivebox"
)
})
Button("Remove Item", role: .destructive) {
viewModel.removeLink(dataService: dataService, objectID: item.objectID)
}
if let author = item.author {
Button(
action: {
viewModel.searchTerm = "author:\"\(author)\""
},
label: {
Label(String("More by \(author)"), systemImage: "person")
}
)
}
}, label: {
Label(
item.isArchived ? "Unarchive" : "Archive",
systemImage: item.isArchived ? "tray.and.arrow.down.fill" : "archivebox"
)
})
Button("Remove Item", role: .destructive) {
viewModel.removeLink(dataService: dataService, objectID: item.objectID)
}
if let author = item.author {
} else {
Button(
action: {
viewModel.searchTerm = "author:\"\(author)\""
},
label: {
Label(String("More by \(author)"), systemImage: "person")
}
action: { viewModel.undeleteItem(dataService: dataService, itemID: item.unwrappedID) },
label: { Label("Undelete", systemImage: "trash.slash") }
)
}
}

View file

@ -325,17 +325,21 @@ import Views
dataService.removeLink(objectID: objectID)
Snackbar.show(message: "Link deleted", undoAction: {
Task {
if await dataService.undeleteItem(itemID: itemID) {
Snackbar.show(message: "Link undeleted")
} else {
Snackbar.show(message: "Error. Check trash to recover.")
}
}
self.undeleteItem(dataService: dataService, itemID: itemID)
})
}
}
func undeleteItem(dataService: DataService, itemID: String) {
Task {
if await dataService.undeleteItem(itemID: itemID) {
Snackbar.show(message: "Link undeleted")
} else {
Snackbar.show(message: "Error. Check trash to recover.")
}
}
}
func getOrCreateLabel(dataService: DataService, named: String, color: String) -> LinkedItemLabel? {
if let label = LinkedItemLabel.named(named, inContext: dataService.viewContext) {
return label