RoomsListView.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // RoomsListView.swift
  3. // Chat
  4. //
  5. // Created by Sergey Tarasov on 10.08.2022.
  6. //
  7. import SwiftUI
  8. struct RoomsListView: View {
  9. @StateObject var store: RoomsListStore = RoomsListStore()
  10. var body: some View {
  11. Group {
  12. if store.rooms.isEmpty {
  13. ProgressView()
  14. } else {
  15. List(store.rooms.indices, id: \.self) { index in
  16. RoomsListCellView(
  17. roomID: store.rooms[index].id,
  18. title: store.rooms[index].name,
  19. lastMessage: "Сообщение \(index)",
  20. lastMessageTime: "14:\(Int.random(in: 10...50))",
  21. unreadMessagesCount: Int.random(in: 1...100)
  22. )
  23. }
  24. .listStyle(.plain)
  25. }
  26. }
  27. .onAppear {
  28. store.fetchRooms()
  29. }
  30. }
  31. }
  32. struct RoomsListView_Previews: PreviewProvider {
  33. static var store: RoomsListStore = RoomsListStore()
  34. static var previews: some View {
  35. NavigationView {
  36. RoomsListView(store: store)
  37. .onAppear {
  38. store.rooms = [
  39. .init(id: "Jid", name: "Room title 1"),
  40. .init(id: "Jid", name: "Room title 2"),
  41. .init(id: "Jid", name: "Room title 3"),
  42. .init(id: "Jid", name: "Room title 4"),
  43. .init(id: "Jid", name: "Room title 5"),
  44. .init(id: "Jid", name: "Room title 6"),
  45. .init(id: "Jid", name: "Room title 7")
  46. ]
  47. }
  48. }
  49. }
  50. }