2024-06-19 15:15:27 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChatsListScreen: View {
|
|
|
|
@EnvironmentObject var store: AppStore
|
|
|
|
|
2024-08-06 12:14:00 +00:00
|
|
|
@State private var isShowingAddScreen = 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-06 12:14:00 +00:00
|
|
|
ChatsScreenHeader(isShowingAddScreen: $isShowingAddScreen)
|
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-06 12:14:00 +00:00
|
|
|
.sheet(isPresented: $isShowingAddScreen) {
|
|
|
|
CreateRoomScreen()
|
|
|
|
.transition(.move(edge: .bottom))
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct ChatsScreenHeader: View {
|
2024-08-06 12:14:00 +00:00
|
|
|
@Binding var isShowingAddScreen: Bool
|
|
|
|
|
2024-06-19 15:15:27 +00:00
|
|
|
var body: some View {
|
|
|
|
ZStack {
|
|
|
|
// bg
|
2024-07-04 08:21:12 +00:00
|
|
|
Color.Material.Background.dark
|
2024-06-19 15:15:27 +00:00
|
|
|
.ignoresSafeArea()
|
|
|
|
|
|
|
|
// title
|
|
|
|
Text(L10n.Chats.title)
|
|
|
|
.font(.head2)
|
2024-07-04 08:21:12 +00:00
|
|
|
.foregroundColor(Color.Material.Text.main)
|
2024-06-19 15:15:27 +00:00
|
|
|
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
2024-08-06 12:14:00 +00:00
|
|
|
Image(systemName: "square.and.pencil")
|
2024-07-04 08:21:12 +00:00
|
|
|
.foregroundColor(.Material.Elements.active)
|
2024-06-19 15:15:27 +00:00
|
|
|
.tappablePadding(.symmetric(12)) {
|
2024-08-06 12:14:00 +00:00
|
|
|
isShowingAddScreen = true
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal, 16)
|
|
|
|
}
|
|
|
|
.frame(height: 44)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|