mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add "All Posts" grouping back to CollectionListView
This commit is contained in:
parent
0887638841
commit
e8301b7eb4
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user