diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index f7ffd51..46f1b3b 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -1,42 +1,37 @@ import SwiftUI struct ContentView: View { @ObservedObject var postStore: PostStore @State private var selectedCollection: PostCollection? = allPostsCollection var body: some View { NavigationView { CollectionSidebar(selectedCollection: $selectedCollection) PostList( title: selectedCollection?.title ?? allPostsCollection.title, posts: showPosts(for: selectedCollection ?? allPostsCollection) ) - .toolbar { - NavigationLink(destination: PostEditor(post: Post())) { - Image(systemName: "square.and.pencil") - } - } Text("Select a post, or create a new draft.") .foregroundColor(.secondary) } .environmentObject(postStore) } func showPosts(for collection: PostCollection) -> [Post] { if collection == allPostsCollection { return postStore.posts } else { return postStore.posts.filter { $0.collection.title == collection.title } } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView(postStore: testPostStore) } } diff --git a/Shared/Post/PostList.swift b/Shared/Post/PostList.swift index eabcad9..41a6393 100644 --- a/Shared/Post/PostList.swift +++ b/Shared/Post/PostList.swift @@ -1,33 +1,40 @@ import SwiftUI struct PostList: View { @EnvironmentObject var postStore: PostStore var title: String var posts: [Post] var body: some View { List { Text(pluralizedPostCount(for: posts)) .foregroundColor(.secondary) ForEach(posts) { post in PostCell(post: post) } } .navigationTitle(title) + .toolbar { + Button(action: { + print("Creating New Draft!") + }, label: { + Image(systemName: "square.and.pencil") + }) + } } func pluralizedPostCount(for posts: [Post]) -> String { if posts.count == 1 { return "1 post" } else { return "\(posts.count) posts" } } } struct PostList_Previews: PreviewProvider { static var previews: some View { PostList(title: "Posts", posts: testPostData) .environmentObject(testPostStore) } }