79 lines
2.3 KiB
Swift
79 lines
2.3 KiB
Swift
import SwiftUI
|
|
|
|
struct ChatsListScreen: View {
|
|
@EnvironmentObject var store: AppStore
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
// Background color
|
|
Color.Material.Background.light
|
|
.ignoresSafeArea()
|
|
|
|
// Content
|
|
VStack(spacing: 0) {
|
|
// Header
|
|
SharedNavigationBar(
|
|
centerText: .init(text: L10n.Chats.title),
|
|
rightButton: .init(
|
|
image: Image(systemName: "square.and.pencil"),
|
|
action: {
|
|
store.dispatch(.changeFlow(.createConversation))
|
|
}
|
|
)
|
|
)
|
|
|
|
// Chats list
|
|
if !store.state.chatsState.chats.isEmpty {
|
|
List {
|
|
ForEach(store.state.chatsState.chats) { chat in
|
|
ChatsRow(chat: chat)
|
|
}
|
|
}
|
|
.listStyle(.plain)
|
|
.background(Color.Material.Background.light)
|
|
} 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)
|
|
.foregroundColor(Color.Material.Text.main)
|
|
.font(.body2)
|
|
Spacer()
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 4)
|
|
Rectangle()
|
|
.frame(maxWidth: .infinity)
|
|
.frame(height: 1)
|
|
.foregroundColor(.Material.Background.dark)
|
|
}
|
|
.sharedListRow()
|
|
.onTapGesture {
|
|
store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant)))
|
|
}
|
|
}
|
|
}
|