another.im-ios/ConversationsClassic/View/Contacts/ContactsScreen.swift

176 lines
6.5 KiB
Swift
Raw Normal View History

2024-08-11 00:28:01 +00:00
import SwiftUI
struct ContactsScreen: View {
2024-08-11 14:02:18 +00:00
@EnvironmentObject var navigation: NavigationStore
2024-08-11 00:28:01 +00:00
@EnvironmentObject var clientsStore: ClientsStore
2024-08-11 11:39:17 +00:00
@StateObject var rostersStore = RostersStore(clientsPublisher: ClientsStore.shared.$clients)
2024-08-11 00:28:01 +00:00
// @State private var addPanelPresented = false
// @State private var isErrorAlertPresented = false
// @State private var errorAlertMessage = ""
// @State private var isShowingLoader = false
var body: some View {
ZStack {
// Background color
Color.Material.Background.light
.ignoresSafeArea()
// Content
VStack(spacing: 0) {
// Header
SharedNavigationBar(
centerText: .init(text: L10n.Contacts.title),
rightButton: .init(
image: Image(systemName: "plus"),
action: {
2024-08-11 14:02:18 +00:00
withAnimation {
navigation.flow = .main(.contacts(.add))
}
2024-08-11 00:28:01 +00:00
// addPanelPresented = true
}
)
)
// Contacts list
2024-08-11 14:02:18 +00:00
if !rostersStore.rosters.isEmpty {
2024-08-11 00:28:01 +00:00
List {
2024-08-11 14:02:18 +00:00
ForEach(rostersStore.rosters) { roster in
2024-08-11 00:28:01 +00:00
ContactsScreenRow(
roster: roster
// isErrorAlertPresented: $isErrorAlertPresented,
// errorAlertMessage: $errorAlertMessage,
// isShowingLoader: $isShowingLoader
)
}
}
.listStyle(.plain)
.background(Color.Material.Background.light)
} else {
Spacer()
}
// Tab bar
SharedTabBar()
}
}
2024-08-11 14:02:18 +00:00
// .task {
// await fetchRosters()
// }
2024-08-11 00:28:01 +00:00
// .loadingIndicator(isShowingLoader)
// .fullScreenCover(isPresented: $addPanelPresented) {
// AddContactOrChannelScreen(isPresented: $addPanelPresented)
// }
// .alert(isPresented: $isErrorAlertPresented) {
// Alert(
// title: Text(L10n.Global.Error.title),
// message: Text(errorAlertMessage),
// dismissButton: .default(Text(L10n.Global.ok))
// )
// }
}
2024-08-11 14:02:18 +00:00
// private func fetchRosters() async {
// let jids = clientsStore.clients
// .filter { $0.state != .disabled }
// .map { $0.credentials.bareJid }
//
// do {
// try await withThrowingTaskGroup(of: [Roster].self) { group in
// for jid in jids {
// group.addTask {
// try await Roster.fetchAll(for: jid)
// }
// }
//
// var allRosters: [Roster] = []
// for try await rosters in group {
// allRosters.append(contentsOf: rosters)
// }
// self.rosters = allRosters.sorted { $0.contactBareJid < $1.contactBareJid }
// }
// } catch {}
// }
2024-08-11 00:28:01 +00:00
}
private struct ContactsScreenRow: View {
var roster: Roster
// @State private var isShowingMenu = false
// @State private var isDeleteAlertPresented = false
//
// @Binding var isErrorAlertPresented: Bool
// @Binding var errorAlertMessage: String
// @Binding var isShowingLoader: Bool
var body: some View {
SharedListRow(
iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter),
text: roster.contactBareJid
)
// .onTapGesture {
// store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid)))
// }
// .onLongPressGesture {
// isShowingMenu.toggle()
// }
// .swipeActions(edge: .trailing, allowsFullSwipe: false) {
// Button {
// isDeleteAlertPresented = true
// } label: {
// Label(L10n.Contacts.sendMessage, systemImage: "trash")
// }
// .tint(Color.red)
// }
// .contextMenu {
// Button(L10n.Contacts.sendMessage, systemImage: "message") {
// store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid)))
// }
// Divider()
//
// Button(L10n.Contacts.editContact) {
// print("Edit contact")
// }
//
// Button(L10n.Contacts.selectContact) {
// print("Select contact")
// }
//
// Divider()
// Button(L10n.Contacts.deleteContact, systemImage: "trash", role: .destructive) {
// isDeleteAlertPresented = true
// }
// }
// .actionSheet(isPresented: $isDeleteAlertPresented) {
// ActionSheet(
// title: Text(L10n.Contacts.Delete.title),
// message: Text(L10n.Contacts.Delete.message),
// buttons: [
// .destructive(Text(L10n.Contacts.Delete.deleteFromDevice)) {
// store.dispatch(.rostersAction(.markRosterAsLocallyDeleted(ownerJID: roster.bareJid, contactJID: roster.contactBareJid)))
// },
// .destructive(Text(L10n.Contacts.Delete.deleteCompletely)) {
// isShowingLoader = true
// store.dispatch(.rostersAction(.deleteRoster(ownerJID: roster.bareJid, contactJID: roster.contactBareJid)))
// },
// .cancel(Text(L10n.Global.cancel))
// ]
// )
// }
// .onChange(of: store.state.rostersState.rosters) { _ in
// endOfDeleting()
// }
// .onChange(of: store.state.rostersState.deleteRosterError) { _ in
// endOfDeleting()
// }
}
// private func endOfDeleting() {
// if isShowingLoader {
// isShowingLoader = false
// if let error = store.state.rostersState.deleteRosterError {
// errorAlertMessage = error
// isErrorAlertPresented = true
// }
// }
// }
}