Fetch collection name for post list cell if showing all posts

This commit is contained in:
Angelo Stavrow 2020-10-01 17:12:28 -04:00
parent c55636df89
commit 6131f9e068
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 15 additions and 3 deletions

View File

@ -3,9 +3,12 @@ import SwiftUI
struct PostListFilteredView: View {
@EnvironmentObject var model: WriteFreelyModel
@FetchRequest(entity: WFACollection.entity(), sortDescriptors: []) var collections: FetchedResults<WFACollection>
var fetchRequest: FetchRequest<WFAPost>
var showAllPosts: Bool
init(filter: String?, showAllPosts: Bool) {
self.showAllPosts = showAllPosts
if showAllPosts {
fetchRequest = FetchRequest<WFAPost>(
entity: WFAPost.entity(),
@ -37,7 +40,16 @@ struct PostListFilteredView: View {
tag: post,
selection: $model.selectedPost
) {
PostCellView(post: post)
if showAllPosts {
if let collection = collections.filter { $0.alias == post.collectionAlias }.first {
PostCellView(post: post, collectionName: collection.title)
} else {
let collectionName = model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
PostCellView(post: post, collectionName: collectionName)
}
} else {
PostCellView(post: post)
}
}
.deleteDisabled(post.status != PostStatus.local.rawValue)
}

View File

@ -7,12 +7,12 @@
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>