import SwiftUI struct ChatsListScreen: View { @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router var body: some View { ZStack { // Background color Color.Material.Background.light .ignoresSafeArea() // Content VStack(spacing: 0) { // Header SharedNavigationBar( centerText: .init(text: L10n.ChatsList.title), rightButton: .init( image: Image(systemName: "square.and.pencil"), action: { router.showScreen(.fullScreenCover) { _ in ChatsCreateScreenMain() } } ) ) // Chats list if !wrapper.activeChats.isEmpty { List { ForEach(wrapper.activeChats) { ChatsRow(chat: $0) } } .listStyle(.plain) .background(Color.Material.Background.light) } else { Spacer() } } } } } private struct ChatsRow: View { @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router var chat: Chat var body: some View { SharedListRow(iconType: .charCircle(chat.name), text: chat.name, controlType: .none) .onTapGesture { Task { router.showModal { LoadingScreen() } defer { router.dismissModal() } do { guard let model = wrapper.chat(with: chat) else { throw AimErrors.wrongContact } router.showScreen(.push) { _ in ConversationScreen(chatWrapper: model) .navigationBarHidden(true) } } catch { router.showAlert( .alert, title: L10n.Global.Error.title, subtitle: L10n.Conversation.startError ) { Button(L10n.Global.ok, role: .cancel) {} } } } } } }