// // RoomsListView.swift // Chat // // Created by Sergey Tarasov on 10.08.2022. // import SwiftUI struct RoomsListView: View { @Environment(\.colorScheme) var colorScheme @ObservedObject var viewModel: RoomsListViewModel var body: some View { Group { if viewModel.rooms.isEmpty { ProgressView() } else { List { ForEach(viewModel.rooms.indices, id: \.self) { index in ZStack { HStack { Image(systemName: "person.crop.circle") .resizable() .scaledToFit() .foregroundColor(.secondary.opacity(0.5)) .padding(.vertical, 8) VStack(alignment: .leading, spacing: 0) { HStack { Text(viewModel.rooms[index].name) Spacer() Text("23:04") .font(.callout) .foregroundColor(.secondary) } .padding(.vertical, 4) HStack { VStack { Text("Сообщение \(index)") .foregroundColor(.secondary) Spacer() } Spacer() Text("\(index)") .font(.callout) .foregroundColor(colorScheme == .light ? .white : .black) .padding(.horizontal, 6) .background( Capsule().foregroundColor(.secondary) ) } .padding(.vertical, 6) } } .foregroundColor(.primary) .frame(height: 60) NavigationLink { ChatView(viewModel: ChatViewModel(with: viewModel.rooms[index].jidString)) } label: { EmptyView() } .opacity(0.0) } } } .listStyle(.plain) } } .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button { viewModel.fetchChatList() } label: { Image(systemName: "arrow.counterclockwise") } } } } } struct RoomsListView_Previews: PreviewProvider { static var viewModel: RoomsListViewModel = RoomsListViewModel() static var previews: some View { Group { NavigationView { RoomsListView(viewModel: viewModel) } NavigationView { RoomsListView(viewModel: viewModel) } .preferredColorScheme(.dark) } } }