Source code for the WriteFreely SwiftUI app for iOS, iPadOS, and macOS
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

45 linhas
1.5 KiB

  1. import SwiftUI
  2. struct CollectionListView: View {
  3. @EnvironmentObject var model: WriteFreelyModel
  4. @Environment(\.managedObjectContext) var moc
  5. @FetchRequest(
  6. entity: WFACollection.entity(),
  7. sortDescriptors: [NSSortDescriptor(keyPath: \WFACollection.title, ascending: true)]
  8. ) var collections: FetchedResults<WFACollection>
  9. var body: some View {
  10. List {
  11. NavigationLink(destination: PostListView(selectedCollection: nil, showAllPosts: true)) {
  12. Text("All Posts")
  13. }
  14. NavigationLink(destination: PostListView(selectedCollection: nil, showAllPosts: false)) {
  15. Text(model.account.server == "https://write.as" ? "Anonymous" : "Drafts")
  16. }
  17. Section(header: Text("Your Blogs")) {
  18. ForEach(collections, id: \.alias) { collection in
  19. NavigationLink(
  20. destination: PostListView(selectedCollection: collection, showAllPosts: false)
  21. ) {
  22. Text(collection.title)
  23. }
  24. }
  25. }
  26. }
  27. .navigationTitle("Collections")
  28. .listStyle(SidebarListStyle())
  29. }
  30. }
  31. struct CollectionListView_Previews: PreviewProvider {
  32. static var previews: some View {
  33. let context = LocalStorageManager.persistentContainer.viewContext
  34. let model = WriteFreelyModel()
  35. return CollectionListView()
  36. .environment(\.managedObjectContext, context)
  37. .environmentObject(model)
  38. }
  39. }