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

79 lines
2.3 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
2024-08-07 08:36:33 +00:00
SharedNavigationBar(
centerText: SharedNavBarText(text: L10n.Chats.title),
rightButton: SharedNavBarButton(
image: Image(systemName: "square.and.pencil"),
action: {
store.dispatch(.changeFlow(.createConversation))
}
)
)
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()
}
}
}
}
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
}
}
}