another.im-ios/Monal/another.im/Views/Main/ChatList/ChatsListScreen.swift
2024-11-23 17:23:56 +01:00

83 lines
2.7 KiB
Swift

import SwiftUI
struct ChatsListScreen: View {
@EnvironmentObject var wrapper: MonalXmppWrapper
@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: MonalXmppWrapper
@Environment(\.router) var router
var chat: Chat
var body: some View {
Text("dump")
SharedListRow(iconType: .charCircle(chat.name), text: chat.name, controlType: .none)
.onTapGesture {
Task {
router.showModal {
LoadingScreen()
}
defer {
router.dismissModal()
}
do {
// try? await clientsStore.addRosterForNewChatIfNeeded(chat)
// let (messages, attachments, settings) = try await clientsStore.conversationStores(for: chat)
// router.showScreen(.push) { _ in
// ConversationScreen(messagesStore: messages, attachments: attachments, settings: settings)
// .navigationBarHidden(true)
// }
} catch {
router.showAlert(
.alert,
title: L10n.Global.Error.title,
subtitle: L10n.Conversation.startError
) {
Button(L10n.Global.ok, role: .cancel) {}
}
}
}
}
}
}