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 {
|
NavigationView {
|
||||||
SidebarView()
|
SidebarView()
|
||||||
|
|
||||||
PostListView(selectedCollection: nil)
|
PostListView(selectedCollection: nil, showAllPosts: true)
|
||||||
|
|
||||||
Text("Select a post, or create a new local draft.")
|
Text("Select a post, or create a new local draft.")
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
|
@ -11,16 +11,16 @@ struct CollectionListView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
// NavigationLink(destination: PostListView(selectedCollection: CollectionListModel.allPostsCollection)) {
|
NavigationLink(destination: PostListView(selectedCollection: nil, showAllPosts: true)) {
|
||||||
// Text(CollectionListModel.allPostsCollection.title)
|
Text("All Posts")
|
||||||
// }
|
}
|
||||||
NavigationLink(destination: PostListView(selectedCollection: nil)) {
|
NavigationLink(destination: PostListView(selectedCollection: nil, showAllPosts: false)) {
|
||||||
Text(model.account.server == "https://write.as" ? "Anonymous" : "Drafts")
|
Text(model.account.server == "https://write.as" ? "Anonymous" : "Drafts")
|
||||||
}
|
}
|
||||||
Section(header: Text("Your Blogs")) {
|
Section(header: Text("Your Blogs")) {
|
||||||
ForEach(collections, id: \.alias) { collection in
|
ForEach(collections, id: \.alias) { collection in
|
||||||
NavigationLink(
|
NavigationLink(
|
||||||
destination: PostListView(selectedCollection: collection)
|
destination: PostListView(selectedCollection: collection, showAllPosts: false)
|
||||||
) {
|
) {
|
||||||
Text(collection.title)
|
Text(collection.title)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import SwiftUI
|
|||||||
struct PostListView: View {
|
struct PostListView: View {
|
||||||
@EnvironmentObject var model: WriteFreelyModel
|
@EnvironmentObject var model: WriteFreelyModel
|
||||||
@State var selectedCollection: WFACollection?
|
@State var selectedCollection: WFACollection?
|
||||||
|
@State var showAllPosts: Bool = false
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
@State private var isPresentingSettings = false
|
@State private var isPresentingSettings = false
|
||||||
@ -24,7 +25,9 @@ struct PostListView: View {
|
|||||||
}
|
}
|
||||||
.environmentObject(model)
|
.environmentObject(model)
|
||||||
.navigationTitle(
|
.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 {
|
.toolbar {
|
||||||
ToolbarItem(placement: .primaryAction) {
|
ToolbarItem(placement: .primaryAction) {
|
||||||
@ -80,7 +83,9 @@ struct PostListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle(
|
.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)))
|
.navigationSubtitle(pluralizedPostCount(for: showPosts(for: selectedCollection)))
|
||||||
.toolbar {
|
.toolbar {
|
||||||
@ -109,26 +114,17 @@ struct PostListView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func showPosts(for collection: WFACollection?) -> [Post] {
|
private func showPosts(for collection: WFACollection?) -> [Post] {
|
||||||
var posts: [Post]
|
if showAllPosts {
|
||||||
|
return model.store.posts
|
||||||
if let selectedCollection = collection {
|
|
||||||
posts = model.store.posts.filter { $0.wfPost.collectionAlias == selectedCollection.alias }
|
|
||||||
} else {
|
} 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() {
|
private func reloadFromServer() {
|
||||||
|
Loading…
Reference in New Issue
Block a user