Source code for the WriteFreely SwiftUI app for iOS, iPadOS, and macOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
2.0 KiB

  1. import SwiftUI
  2. struct CollectionListView: View {
  3. @EnvironmentObject var model: WriteFreelyModel
  4. @Environment(\.managedObjectContext) var moc
  5. @FetchRequest(entity: WFACollection.entity(), sortDescriptors: []) var collections: FetchedResults<WFACollection>
  6. var body: some View {
  7. List {
  8. NavigationLink(destination: PostListView(selectedCollection: CollectionListModel.allPostsCollection)) {
  9. Text(CollectionListModel.allPostsCollection.title)
  10. }
  11. NavigationLink(destination: PostListView(selectedCollection: CollectionListModel.draftsCollection)) {
  12. Text(CollectionListModel.draftsCollection.title)
  13. }
  14. Section(header: Text("Your Blogs")) {
  15. ForEach(collections, id: \.alias) { collection in
  16. NavigationLink(
  17. destination: PostListView(selectedCollection: PostCollection(title: collection.title))
  18. ) {
  19. Text(collection.title)
  20. }
  21. }
  22. }
  23. }
  24. .navigationTitle("Collections")
  25. .listStyle(SidebarListStyle())
  26. }
  27. }
  28. struct CollectionSidebar_Previews: PreviewProvider {
  29. @Environment(\.managedObjectContext) var moc
  30. static var previews: some View {
  31. let userCollection1 = WFACollection(context: PersistenceManager.persistentContainer.viewContext)
  32. let userCollection2 = WFACollection(context: PersistenceManager.persistentContainer.viewContext)
  33. let userCollection3 = WFACollection(context: PersistenceManager.persistentContainer.viewContext)
  34. userCollection1.title = "Collection 1"
  35. userCollection2.title = "Collection 2"
  36. userCollection3.title = "Collection 3"
  37. let model = WriteFreelyModel()
  38. model.collections = CollectionListModel()
  39. return CollectionListView()
  40. .environmentObject(model)
  41. .environment(\.managedObjectContext, PersistenceManager.persistentContainer.viewContext)
  42. }
  43. }