2024-08-12 19:29:16 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChatsListScreen: View {
|
2024-08-14 09:29:51 +00:00
|
|
|
@Environment(\.router) var router
|
2024-08-12 19:29:16 +00:00
|
|
|
@EnvironmentObject var clientsStore: ClientsStore
|
|
|
|
|
|
|
|
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: {
|
2024-08-14 09:29:51 +00:00
|
|
|
router.showScreen(.fullScreenCover) { _ in
|
|
|
|
ChatsCreateScreenMain()
|
|
|
|
}
|
2024-08-12 19:29:16 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
// Chats list
|
|
|
|
if !clientsStore.actualChats.isEmpty {
|
|
|
|
List {
|
|
|
|
ForEach(clientsStore.actualChats) { chat in
|
|
|
|
ChatsRow(chat: chat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.listStyle(.plain)
|
|
|
|
.background(Color.Material.Background.light)
|
|
|
|
} else {
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct ChatsRow: View {
|
2024-08-13 08:40:27 +00:00
|
|
|
@Environment(\.router) var router
|
|
|
|
@EnvironmentObject var clientsStore: ClientsStore
|
2024-08-12 19:29:16 +00:00
|
|
|
|
|
|
|
var chat: Chat
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
SharedListRow(iconType: .charCircle(chat.participant), text: chat.participant)
|
|
|
|
.onTapGesture {
|
2024-08-14 09:29:51 +00:00
|
|
|
Task {
|
|
|
|
router.showModal {
|
|
|
|
LoadingScreen()
|
|
|
|
}
|
|
|
|
defer {
|
|
|
|
router.dismissModal()
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
let conversation = try await clientsStore.conversationStore(for: chat)
|
|
|
|
router.showScreen(.push) { _ in
|
|
|
|
ConversationScreen(conversation: conversation)
|
|
|
|
.navigationBarHidden(true)
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
router.showAlert(
|
|
|
|
.alert,
|
|
|
|
title: L10n.Global.Error.title,
|
|
|
|
subtitle: L10n.Conversation.startError
|
|
|
|
) {
|
|
|
|
Button(L10n.Global.ok, role: .cancel) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-12 19:29:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|