2024-07-02 09:56:27 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
2024-09-03 15:13:58 +00:00
|
|
|
struct ContactsPickerView: View {
|
|
|
|
@Environment(\.router) var router
|
|
|
|
@EnvironmentObject var messages: MessagesStore
|
|
|
|
|
|
|
|
@State private var rosters: [Roster] = []
|
2024-07-08 08:58:24 +00:00
|
|
|
@State private var selectedContact: Roster?
|
|
|
|
|
2024-07-02 09:56:27 +00:00
|
|
|
var body: some View {
|
2024-07-08 07:41:35 +00:00
|
|
|
VStack(spacing: 0) {
|
|
|
|
// Contacts list
|
|
|
|
if !rosters.isEmpty {
|
|
|
|
List {
|
|
|
|
ForEach(rosters) { roster in
|
2024-07-08 08:58:24 +00:00
|
|
|
ContactRow(roster: roster, selectedContact: $selectedContact)
|
2024-07-08 07:41:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.listStyle(.plain)
|
|
|
|
.background(Color.Material.Background.light)
|
|
|
|
} else {
|
|
|
|
Spacer()
|
|
|
|
}
|
2024-07-08 08:58:24 +00:00
|
|
|
|
|
|
|
// Send panel
|
|
|
|
Rectangle()
|
|
|
|
.foregroundColor(.Material.Shape.black)
|
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
.frame(height: selectedContact == nil ? 0 : 50)
|
|
|
|
.overlay {
|
|
|
|
HStack {
|
|
|
|
Text(L10n.Attachment.Send.contact)
|
|
|
|
.foregroundColor(.Material.Text.white)
|
|
|
|
.font(.body1)
|
|
|
|
Image(systemName: "arrow.up.circle")
|
|
|
|
.foregroundColor(.Material.Text.white)
|
|
|
|
.font(.body1)
|
|
|
|
.padding(.leading, 8)
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
}
|
|
|
|
.clipped()
|
|
|
|
.onTapGesture {
|
2024-07-10 11:09:59 +00:00
|
|
|
if let selectedContact = selectedContact {
|
2024-09-03 15:13:58 +00:00
|
|
|
messages.sendContact(selectedContact.contactBareJid)
|
|
|
|
router.dismissEnvironment()
|
2024-07-10 11:09:59 +00:00
|
|
|
}
|
2024-07-08 08:58:24 +00:00
|
|
|
}
|
2024-07-08 07:41:35 +00:00
|
|
|
}
|
2024-09-03 15:13:58 +00:00
|
|
|
.task {
|
|
|
|
rosters = await Roster.allActive
|
|
|
|
}
|
2024-07-08 07:41:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct ContactRow: View {
|
|
|
|
var roster: Roster
|
2024-07-08 08:58:24 +00:00
|
|
|
@Binding var selectedContact: Roster?
|
2024-07-08 07:41:35 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2024-08-07 19:07:39 +00:00
|
|
|
SharedListRow(
|
|
|
|
iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter),
|
2024-09-19 16:50:48 +00:00
|
|
|
text: roster.contactBareJid,
|
|
|
|
controlType: .none
|
2024-08-07 19:07:39 +00:00
|
|
|
)
|
2024-07-08 07:41:35 +00:00
|
|
|
.onTapGesture {
|
2024-07-08 08:58:24 +00:00
|
|
|
selectedContact = roster
|
2024-07-08 07:41:35 +00:00
|
|
|
}
|
2024-07-02 09:56:27 +00:00
|
|
|
}
|
|
|
|
}
|