From e8301b7eb441498c86ae6edca857f60b308ad853 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Fri, 4 Sep 2020 14:53:53 -0400 Subject: [PATCH] Add "All Posts" grouping back to CollectionListView --- Shared/Navigation/ContentView.swift | 2 +- .../PostCollection/CollectionListView.swift | 10 +++--- Shared/PostList/PostListView.swift | 36 +++++++++---------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index 6121a89..d95911c 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -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) diff --git a/Shared/PostCollection/CollectionListView.swift b/Shared/PostCollection/CollectionListView.swift index 0485d8a..9606fcc 100644 --- a/Shared/PostCollection/CollectionListView.swift +++ b/Shared/PostCollection/CollectionListView.swift @@ -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) } diff --git a/Shared/PostList/PostListView.swift b/Shared/PostList/PostListView.swift index d5e96eb..76c0c71 100644 --- a/Shared/PostList/PostListView.swift +++ b/Shared/PostList/PostListView.swift @@ -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() {