another.im-ios/Monal/another.im/Views/Main/ChatList/ChatsListScreen.swift

83 lines
2.7 KiB
Swift
Raw Normal View History

2024-11-23 16:23:49 +00:00
import SwiftUI
struct ChatsListScreen: View {
2024-11-23 16:23:56 +00:00
@EnvironmentObject var wrapper: MonalXmppWrapper
2024-11-23 16:23:49 +00:00
@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
2024-11-23 16:23:56 +00:00
if !wrapper.activeChats.isEmpty {
2024-11-23 16:23:49 +00:00
List {
2024-11-23 16:23:56 +00:00
ForEach(wrapper.activeChats) {
ChatsRow(chat: $0)
2024-11-23 16:23:49 +00:00
}
}
.listStyle(.plain)
.background(Color.Material.Background.light)
} else {
Spacer()
}
}
}
}
}
private struct ChatsRow: View {
2024-11-23 16:23:56 +00:00
@EnvironmentObject var wrapper: MonalXmppWrapper
2024-11-23 16:23:49 +00:00
@Environment(\.router) var router
var chat: Chat
var body: some View {
2024-11-23 16:23:56 +00:00
Text("dump")
SharedListRow(iconType: .charCircle(chat.name), text: chat.name, controlType: .none)
2024-11-23 16:23:49 +00:00
.onTapGesture {
Task {
router.showModal {
LoadingScreen()
}
defer {
router.dismissModal()
}
do {
2024-11-23 16:23:56 +00:00
// 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)
// }
2024-11-23 16:23:49 +00:00
} catch {
router.showAlert(
.alert,
title: L10n.Global.Error.title,
subtitle: L10n.Conversation.startError
) {
Button(L10n.Global.ok, role: .cancel) {}
}
}
}
}
}
}