Add "All Posts" grouping back to CollectionListView

This commit is contained in:
Angelo Stavrow 2020-09-04 14:53:53 -04:00
parent 0887638841
commit e8301b7eb4
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 22 additions and 26 deletions

View File

@ -7,7 +7,7 @@ struct ContentView: View {
NavigationView {
SidebarView()
PostListView(selectedCollection: nil)
PostListView(selectedCollection: nil, showAllPosts: true)
Text("Select a post, or create a new local draft.")
.foregroundColor(.secondary)

View File

@ -11,16 +11,16 @@ struct CollectionListView: View {
var body: some View {
List {
// NavigationLink(destination: PostListView(selectedCollection: CollectionListModel.allPostsCollection)) {
// Text(CollectionListModel.allPostsCollection.title)
// }
NavigationLink(destination: PostListView(selectedCollection: nil)) {
NavigationLink(destination: PostListView(selectedCollection: nil, showAllPosts: true)) {
Text("All Posts")
}
NavigationLink(destination: PostListView(selectedCollection: nil, showAllPosts: false)) {
Text(model.account.server == "https://write.as" ? "Anonymous" : "Drafts")
}
Section(header: Text("Your Blogs")) {
ForEach(collections, id: \.alias) { collection in
NavigationLink(
destination: PostListView(selectedCollection: collection)
destination: PostListView(selectedCollection: collection, showAllPosts: false)
) {
Text(collection.title)
}

View File

@ -3,6 +3,7 @@ import SwiftUI
struct PostListView: View {
@EnvironmentObject var model: WriteFreelyModel
@State var selectedCollection: WFACollection?
@State var showAllPosts: Bool = false
#if os(iOS)
@State private var isPresentingSettings = false
@ -24,7 +25,9 @@ struct PostListView: View {
}
.environmentObject(model)
.navigationTitle(
selectedCollection?.title ?? (model.account.server == "https://write.as" ? "Anonymous" : "Drafts")
showAllPosts ? "All Posts" : selectedCollection?.title ?? (
model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
)
)
.toolbar {
ToolbarItem(placement: .primaryAction) {
@ -80,7 +83,9 @@ struct PostListView: View {
}
}
.navigationTitle(
selectedCollection?.title ?? (model.account.server == "https://write.as" ? "Anonymous" : "Drafts")
showAllPosts ? "All Posts" : selectedCollection?.title ?? (
model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
)
)
.navigationSubtitle(pluralizedPostCount(for: showPosts(for: selectedCollection)))
.toolbar {
@ -109,26 +114,17 @@ struct PostListView: View {
}
private func showPosts(for collection: WFACollection?) -> [Post] {
var posts: [Post]
if let selectedCollection = collection {
posts = model.store.posts.filter { $0.wfPost.collectionAlias == selectedCollection.alias }
if showAllPosts {
return model.store.posts
} else {
posts = model.store.posts.filter { $0.wfPost.collectionAlias == nil }
var posts: [Post]
if let selectedCollection = collection {
posts = model.store.posts.filter { $0.wfPost.collectionAlias == selectedCollection.alias }
} else {
posts = model.store.posts.filter { $0.wfPost.collectionAlias == nil }
}
return posts
}
// for post in model.store.posts {
// print("Post '\(post.wfPost.title ?? "Untitled")' in \(post.collection?.title ?? "No collection")")
// }
// if collection == CollectionListModel.allPostsCollection {
// posts = model.store.posts
// } else if collection == CollectionListModel.draftsCollection {
// posts = model.store.posts.filter { $0.collection == nil }
// } else {
// posts = model.store.posts.filter { $0.collection == collection }
// }
return posts
}
private func reloadFromServer() {