12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // RoomsListView.swift
- // Chat
- //
- // Created by Sergey Tarasov on 10.08.2022.
- //
- import SwiftUI
- struct RoomsListView: View {
- @StateObject var store: RoomsListStore = RoomsListStore()
- var body: some View {
- Group {
- if store.rooms.isEmpty {
- ProgressView()
- } else {
- List(store.rooms.indices, id: \.self) { index in
- RoomsListCellView(
- roomID: store.rooms[index].id,
- title: store.rooms[index].name,
- lastMessage: "Сообщение \(index)",
- lastMessageTime: "14:\(Int.random(in: 10...50))",
- unreadMessagesCount: Int.random(in: 1...100)
- )
- }
- .listStyle(.plain)
- }
- }
- .onAppear {
- store.fetchRooms()
- }
- }
- }
- struct RoomsListView_Previews: PreviewProvider {
- static var store: RoomsListStore = RoomsListStore()
- static var previews: some View {
- NavigationView {
- RoomsListView(store: store)
- .onAppear {
- store.rooms = [
- .init(id: "Jid", name: "Room title 1"),
- .init(id: "Jid", name: "Room title 2"),
- .init(id: "Jid", name: "Room title 3"),
- .init(id: "Jid", name: "Room title 4"),
- .init(id: "Jid", name: "Room title 5"),
- .init(id: "Jid", name: "Room title 6"),
- .init(id: "Jid", name: "Room title 7")
- ]
- }
- }
- }
- }
|