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

85 lines
2.6 KiB
Swift
Raw Permalink 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
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-25 10:51:00 +00:00
guard let model = wrapper.chat(with: chat) else {
throw AimErrors.wrongContact
}
router.showScreen(.push) { _ in
ConversationScreen()
.navigationBarHidden(true)
.environmentObject(model)
}
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) {}
}
}
}
}
}
}