conversations-classic-ios/ConversationsClassic/View/Screens/ChatsListScreen.swift

97 lines
2.7 KiB
Swift
Raw Normal View History

2024-06-19 15:15:27 +00:00
import SwiftUI
struct ChatsListScreen: View {
@EnvironmentObject var store: AppStore
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
ChatsScreenHeader()
// 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()
}
}
}
}
private struct ChatsScreenHeader: View {
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()
Image(systemName: "plus")
2024-07-04 08:21:12 +00:00
.foregroundColor(.Material.Elements.active)
2024-06-19 15:15:27 +00:00
.tappablePadding(.symmetric(12)) {
print("Add contact")
}
}
.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
}
}
}