2024-06-19 15:15:27 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChatsListScreen: View {
|
|
|
|
@EnvironmentObject var store: AppStore
|
|
|
|
|
2024-08-07 15:13:43 +00:00
|
|
|
@State private var isCretePanelPresented = false
|
|
|
|
|
2024-06-19 15:15:27 +00:00
|
|
|
var body: some View {
|
|
|
|
ZStack {
|
|
|
|
// Background color
|
2024-07-04 08:21:12 +00:00
|
|
|
Color.Material.Background.light
|
2024-06-19 15:15:27 +00:00
|
|
|
.ignoresSafeArea()
|
|
|
|
|
|
|
|
// Content
|
|
|
|
VStack(spacing: 0) {
|
|
|
|
// Header
|
2024-08-07 08:36:33 +00:00
|
|
|
SharedNavigationBar(
|
2024-08-07 09:19:53 +00:00
|
|
|
centerText: .init(text: L10n.Chats.title),
|
|
|
|
rightButton: .init(
|
2024-08-07 08:36:33 +00:00
|
|
|
image: Image(systemName: "square.and.pencil"),
|
|
|
|
action: {
|
2024-08-07 15:13:43 +00:00
|
|
|
isCretePanelPresented = true
|
2024-08-07 08:36:33 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2024-06-19 15:15:27 +00:00
|
|
|
|
|
|
|
// Chats list
|
|
|
|
if !store.state.chatsState.chats.isEmpty {
|
|
|
|
List {
|
|
|
|
ForEach(store.state.chatsState.chats) { chat in
|
|
|
|
ChatsRow(chat: chat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.listStyle(.plain)
|
2024-07-04 08:21:12 +00:00
|
|
|
.background(Color.Material.Background.light)
|
2024-06-19 15:15:27 +00:00
|
|
|
} else {
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tab bar
|
|
|
|
SharedTabBar()
|
|
|
|
}
|
|
|
|
}
|
2024-08-07 15:13:43 +00:00
|
|
|
.fullScreenCover(isPresented: $isCretePanelPresented) {
|
|
|
|
ChatsCreateMainScreen(isPresented: $isCretePanelPresented)
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct ChatsRow: View {
|
|
|
|
@EnvironmentObject var store: AppStore
|
|
|
|
|
|
|
|
var chat: Chat
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(spacing: 0) {
|
|
|
|
HStack(spacing: 8) {
|
|
|
|
ZStack {
|
|
|
|
Circle()
|
|
|
|
.frame(width: 44, height: 44)
|
|
|
|
.foregroundColor(.red)
|
|
|
|
Text(chat.participant.firstLetter)
|
|
|
|
.foregroundColor(.white)
|
|
|
|
.font(.body1)
|
|
|
|
}
|
|
|
|
Text(chat.participant)
|
2024-07-04 08:21:12 +00:00
|
|
|
.foregroundColor(Color.Material.Text.main)
|
2024-06-19 15:15:27 +00:00
|
|
|
.font(.body2)
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding(.horizontal, 16)
|
|
|
|
.padding(.vertical, 4)
|
|
|
|
Rectangle()
|
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
.frame(height: 1)
|
2024-07-04 08:21:12 +00:00
|
|
|
.foregroundColor(.Material.Background.dark)
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
.sharedListRow()
|
|
|
|
.onTapGesture {
|
2024-06-20 05:27:13 +00:00
|
|
|
store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant)))
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|