2020-07-31 20:26:37 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
2020-08-04 14:45:46 +00:00
|
|
|
struct CollectionSidebar: View {
|
|
|
|
@EnvironmentObject var postStore: PostStore
|
|
|
|
@Binding var selectedCollection: PostCollection?
|
2020-07-31 20:26:37 +00:00
|
|
|
|
|
|
|
private let collections = [
|
2020-07-31 20:54:21 +00:00
|
|
|
allPostsCollection,
|
2020-07-31 20:26:37 +00:00
|
|
|
defaultDraftCollection,
|
|
|
|
testPostCollection1,
|
|
|
|
testPostCollection2,
|
|
|
|
testPostCollection3
|
|
|
|
]
|
|
|
|
|
|
|
|
var body: some View {
|
2020-08-04 14:45:46 +00:00
|
|
|
List {
|
2020-07-31 20:26:37 +00:00
|
|
|
ForEach(collections) { collection in
|
2020-08-04 14:45:46 +00:00
|
|
|
NavigationLink(
|
|
|
|
destination: PostList(title: collection.title, posts: showPosts(for: collection)).tag(collection)) {
|
|
|
|
Text(collection.title)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.listStyle(SidebarListStyle())
|
|
|
|
}
|
|
|
|
|
|
|
|
func showPosts(for collection: PostCollection) -> [Post] {
|
|
|
|
if collection == allPostsCollection {
|
|
|
|
return postStore.posts
|
|
|
|
} else {
|
|
|
|
return postStore.posts.filter {
|
|
|
|
$0.collection.title == collection.title
|
2020-07-31 20:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|