123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- //
- // ChatListView.swift
- // Chat
- //
- // Created by Sergey Tarasov on 24.07.2022.
- //
- import SwiftUI
- import XMPPFramework
- import XMPPFrameworkSwift
- struct ChatListView: View {
- @Environment(\.colorScheme) var colorScheme
- @ObservedObject var viewModel: ChatListViewModel
- var body: some View {
- Group {
- if viewModel.users.isEmpty {
- ProgressView()
- } else {
- List {
- ForEach(viewModel.users.indices, id: \.self) { index in
- ZStack {
- HStack {
- Image(systemName: "person.crop.circle")
- .resizable()
- .scaledToFit()
- .foregroundColor(.secondary.opacity(0.5))
- Text(viewModel.nicknames[index])
- Spacer()
- }
- .foregroundColor(.primary)
- .frame(height: 30)
- NavigationLink {
- ChatView(viewModel: ChatViewModel(with: viewModel.users[index].jidString))
- } label: {
- EmptyView()
- }
- .opacity(0.0)
- }
- }
- }
- .listStyle(.plain)
- }
- }
- .navigationBarTitleDisplayMode(.inline)
- .toolbar {
- ToolbarItem(placement: .navigationBarTrailing) {
- Button {
- viewModel.fetchChatList()
- } label: {
- Image(systemName: "arrow.counterclockwise")
- }
- }
- }
- }
- }
- struct ChatListView_Previews: PreviewProvider {
- static var viewModel: ChatListViewModel = ChatListViewModel()
- static var previews: some View {
- Group {
- NavigationView {
- ChatListView(viewModel: viewModel)
- }
- NavigationView {
- ChatListView(viewModel: viewModel)
- }
- .preferredColorScheme(.dark)
- }
- }
- }
|