mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
37 lines
1003 B
Swift
37 lines
1003 B
Swift
import SwiftUI
|
|
|
|
struct CollectionSidebar: View {
|
|
@EnvironmentObject var postStore: PostStore
|
|
@Binding var selectedCollection: PostCollection?
|
|
|
|
private let collections = [
|
|
allPostsCollection,
|
|
defaultDraftCollection,
|
|
testPostCollection1,
|
|
testPostCollection2,
|
|
testPostCollection3
|
|
]
|
|
|
|
var body: some View {
|
|
List {
|
|
ForEach(collections) { collection in
|
|
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
|
|
}
|
|
}
|
|
}
|
|
}
|