ChatListView.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // ChatListView.swift
  3. // Chat
  4. //
  5. // Created by Sergey Tarasov on 24.07.2022.
  6. //
  7. import SwiftUI
  8. import XMPPFramework
  9. import XMPPFrameworkSwift
  10. struct ChatListView: View {
  11. @Environment(\.colorScheme) var colorScheme
  12. @ObservedObject var viewModel: ChatListViewModel
  13. var body: some View {
  14. Group {
  15. if viewModel.users.isEmpty {
  16. ProgressView()
  17. } else {
  18. List {
  19. ForEach(viewModel.users.indices, id: \.self) { index in
  20. ZStack {
  21. HStack {
  22. Image(systemName: "person.crop.circle")
  23. .resizable()
  24. .scaledToFit()
  25. .foregroundColor(.secondary.opacity(0.5))
  26. Text(viewModel.nicknames[index])
  27. Spacer()
  28. }
  29. .foregroundColor(.primary)
  30. .frame(height: 30)
  31. NavigationLink {
  32. ChatView(viewModel: ChatViewModel(with: viewModel.users[index].jidString))
  33. } label: {
  34. EmptyView()
  35. }
  36. .opacity(0.0)
  37. }
  38. }
  39. }
  40. .listStyle(.plain)
  41. }
  42. }
  43. .navigationBarTitleDisplayMode(.inline)
  44. .toolbar {
  45. ToolbarItem(placement: .navigationBarTrailing) {
  46. Button {
  47. viewModel.fetchChatList()
  48. } label: {
  49. Image(systemName: "arrow.counterclockwise")
  50. }
  51. }
  52. }
  53. }
  54. }
  55. struct ChatListView_Previews: PreviewProvider {
  56. static var viewModel: ChatListViewModel = ChatListViewModel()
  57. static var previews: some View {
  58. Group {
  59. NavigationView {
  60. ChatListView(viewModel: viewModel)
  61. }
  62. NavigationView {
  63. ChatListView(viewModel: viewModel)
  64. }
  65. .preferredColorScheme(.dark)
  66. }
  67. }
  68. }