Skip to content

Commit

Permalink
Add: new PostListFilter for all non-trashed posts
Browse files Browse the repository at this point in the history
  • Loading branch information
hassaanelgarem committed Apr 12, 2023
1 parent 2585912 commit 1c40a9b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,8 @@ private extension PageListViewController {
return NoResultsText.noTrashedTitle
case .published:
return NoResultsText.noPublishedTitle
case .allNonTrashed:
return ""
}
}

Expand Down
33 changes: 33 additions & 0 deletions WordPress/Classes/ViewRelated/Post/PostListFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Foundation
case draft
case scheduled
case trashed
case allNonTrashed
}

@objc var hasMore: Bool
Expand Down Expand Up @@ -41,6 +42,8 @@ import Foundation
var sortField: AbstractPost.SortField {
switch filterType {
case .draft:
fallthrough
case .allNonTrashed:
return .dateModified
default:
return .dateCreated
Expand Down Expand Up @@ -186,6 +189,36 @@ import Foundation
return filter
}

@objc class func allNonTrashedFilter() -> PostListFilter {
let filterType: Status = .allNonTrashed
let statuses: [BasePost.Status] = [.draft, .pending, .publish, .publishPrivate, .scheduled]

let query =
// Existing non-trashed posts
"(statusAfterSync = status AND status IN (%@))"
// Existing non-trashed posts transitioned to another status but not uploaded yet
+ " OR (statusAfterSync != status AND statusAfterSync IN (%@))"
// Non-trashed posts existing only on the device
+ " OR (postID = %i AND status IN (%@))"
// Include other existing non-trashed posts with `nil` `statusAfterSync`. This is
// unlikely but this ensures that those posts will show up somewhere.
+ " OR (postID > %i AND statusAfterSync = nil AND status IN (%@))"
let predicate = NSPredicate(format: query,
statuses.strings,
statuses.strings,
BasePost.defaultPostIDValue,
statuses.strings,
BasePost.defaultPostIDValue,
statuses.strings)

let title = NSLocalizedString("All", comment: "Title of the drafts filter. This filter shows a list of draft posts.")

This comment has been minimized.

Copy link
@mokagio

mokagio Apr 16, 2023

Contributor

Reminder to please use a reverse-DNS key with localized strings to always provide a unique string translation and avoid localization ambiguities (see #19028).

Thanks! 😄

I noticed this as part of the 22.2 code freeze.


let filter = PostListFilter(title: title, filterType: filterType, predicate: predicate, statuses: statuses)
filter.accessibilityIdentifier = "all"

return filter
}

func predicate(for blog: Blog) -> NSPredicate {
var predicates = [NSPredicate]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ private extension PostListViewController {
return NoResultsText.noTrashedTitle
case .published:
return NoResultsText.noPublishedTitle
case .allNonTrashed:
return ""
}
}

Expand Down

0 comments on commit 1c40a9b

Please sign in to comment.