From 3b6c7748e8a19be6a260f3043b7114033911ce1d Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Thu, 14 Jan 2021 10:28:14 -0500 Subject: [PATCH] Ensure showAllPosts is false when navigating to a given blog --- .../PostCollection/CollectionListView.swift | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Shared/PostCollection/CollectionListView.swift b/Shared/PostCollection/CollectionListView.swift index a084f82..9dbcb22 100644 --- a/Shared/PostCollection/CollectionListView.swift +++ b/Shared/PostCollection/CollectionListView.swift @@ -18,15 +18,16 @@ struct CollectionListView: View { model.selectedCollection == nil && model.showAllPosts }, set: { newValue in if newValue { - self.model.selectedCollection = nil self.model.showAllPosts = true + self.model.selectedCollection = nil } else { // No-op } } - )) { + ), + label: { Text("All Posts") - } + }) NavigationLink( destination: PostListView(), isActive: Binding( @@ -34,27 +35,38 @@ struct CollectionListView: View { model.selectedCollection == nil && !model.showAllPosts }, set: { newValue in if newValue { - self.model.selectedCollection = nil self.model.showAllPosts = false + self.model.selectedCollection = nil } else { // No-op } } - )) { + ), + label: { Text(model.account.server == "https://write.as" ? "Anonymous" : "Drafts") - } + }) Section(header: Text("Your Blogs")) { ForEach(collections, id: \.alias) { collection in NavigationLink( - collection.title, destination: PostListView(), - tag: collection, - selection: $model.selectedCollection + isActive: Binding( + get: { () -> Bool in + model.selectedCollection == collection && !model.showAllPosts + }, set: { newValue in + if newValue { + self.model.showAllPosts = false + self.model.selectedCollection = collection + } else { + // No-op + } + } + ), + label: { Text(collection.title) } ) } } } else { - NavigationLink(destination: PostListView(selectedCollection: nil, showAllPosts: false)) { + NavigationLink(destination: PostListView()) { Text("Drafts") } }