Improve undelete

This commit is contained in:
Jackson Harper 2023-07-12 16:59:17 +08:00
parent 55d24ee52d
commit 52776521f3
6 changed files with 14 additions and 2 deletions

View file

@ -17,6 +17,8 @@ extension LinkedItemFilter {
return LocalText.allGeneric
case .archived:
return LocalText.archivedGeneric
case .deleted:
return "Deleted"
case .hasHighlights:
return LocalText.highlightedGeneric
case .files:

View file

@ -192,7 +192,7 @@ import Views
return itemObjects
}()
if searchTerm.replacingOccurrences(of: " ", with: "").isEmpty {
if searchTerm.replacingOccurrences(of: " ", with: "").isEmpty, LinkedItemFilter(rawValue: appliedFilter) != .deleted {
updateFetchController(dataService: dataService)
} else {
// Don't use FRC for searching. Use server results directly.

View file

@ -6,6 +6,7 @@ public enum ArticleContentStatus: String {
case processing = "PROCESSING"
case succeeded = "SUCCEEDED"
case unknown = "UNKNOWN"
case deleted = "DELETED"
}
public struct ArticleContent {

View file

@ -7,6 +7,7 @@ public enum LinkedItemFilter: String, CaseIterable {
case recommended
case all
case archived
case deleted
case hasHighlights
case files
}
@ -26,6 +27,8 @@ public extension LinkedItemFilter {
return "in:all"
case .archived:
return "in:archive"
case .deleted:
return "in:trash"
case .hasHighlights:
return "has:highlights"
case .files:
@ -73,6 +76,11 @@ public extension LinkedItemFilter {
format: "%K == %@", #keyPath(LinkedItem.isArchived), Int(truncating: true) as NSNumber
)
return NSCompoundPredicate(andPredicateWithSubpredicates: [undeletedPredicate, inArchivePredicate])
case .deleted:
let deletedPredicate = NSPredicate(
format: "%K == %i", #keyPath(LinkedItem.serverSyncStatus), Int64(ServerSyncStatus.needsDeletion.rawValue)
)
return NSCompoundPredicate(andPredicateWithSubpredicates: [deletedPredicate])
case .files:
// include pdf only
let isPDFPredicate = NSPredicate(

View file

@ -43,7 +43,7 @@ public extension DataService {
username: username,
requestCount: requestCount + 1
)
case .succeeded, .unknown:
case .succeeded, .unknown, .deleted:
return fetchedContent
}
}

View file

@ -98,6 +98,7 @@ extension Sequence where Element == InternalLinkedItem {
print("LinkedItems saved succesfully")
} catch {
context.rollback()
print(error)
print("Failed to save LinkedItems: \(error.localizedDescription)")
}
}