remove refresh team action and task

sync3
Razmig Sarkissian 1 month ago
parent 64d0d7c307
commit 74b61c6046
  1. 60
      PadelClub/Views/Navigation/Agenda/EventListView.swift
  2. 74
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift

@ -204,15 +204,15 @@ struct EventListView: View {
}
Divider()
Menu {
Button {
Task {
await pcTournaments.concurrentForEach { tournament in
await tournament.refreshTeamList(forced: true)
}
}
} label: {
Text("M-à-j des inscriptions")
}
// Button {
// Task {
// await pcTournaments.concurrentForEach { tournament in
// await tournament.refreshTeamList(forced: true)
// }
// }
// } label: {
// Text("M-à-j des inscriptions")
// }
Button {
pcTournaments.forEach { tournament in
@ -413,27 +413,27 @@ struct EventListView: View {
private func _tournamentView(_ tournament: Tournament) -> some View {
NavigationLink(value: tournament) {
TournamentCellView(tournament: tournament)
.onReceive(NotificationCenter.default.publisher(for: NSNotification.Name.CollectionDidLoad), perform: { notification in
if let store = notification.object as? SyncedCollection<TeamRegistration> {
if store.storeId == tournament.id {
if tournament.store?.fileCollectionsAllLoaded() == true {
tournament.lastTeamRefresh = nil
}
}
}
if let store = notification.object as? SyncedCollection<PlayerRegistration> {
if store.storeId == tournament.id {
if tournament.store?.fileCollectionsAllLoaded() == true {
tournament.lastTeamRefresh = nil
}
}
}
})
.id(tournament.lastTeamRefresh)
.task(priority: .background) {
await tournament.refreshTeamList(forced: false)
}
// .onReceive(NotificationCenter.default.publisher(for: NSNotification.Name.CollectionDidLoad), perform: { notification in
//
// if let store = notification.object as? SyncedCollection<TeamRegistration> {
// if store.storeId == tournament.id {
// if tournament.store?.fileCollectionsAllLoaded() == true {
// tournament.lastTeamRefresh = nil
// }
// }
// }
// if let store = notification.object as? SyncedCollection<PlayerRegistration> {
// if store.storeId == tournament.id {
// if tournament.store?.fileCollectionsAllLoaded() == true {
// tournament.lastTeamRefresh = nil
// }
// }
// }
// })
// .id(tournament.lastTeamRefresh)
// .task(priority: .background) {
// await tournament.refreshTeamList(forced: false)
// }
}
.listRowView(isActive: tournament.enableOnlineRegistration, color: .green, hideColorVariation: true)
.onChange(of: tournament.isTemplate) {

@ -247,9 +247,9 @@ struct InscriptionManagerView: View {
}
if tournament.enableOnlineRegistration {
RowButtonView("Rafraîchir la liste", cornerRadius: 20) {
await _refreshList(forced: true)
}
// RowButtonView("Rafraîchir la liste", cornerRadius: 20) {
// await _refreshList(forced: true)
// }
} else if tournament.onlineRegistrationCanBeEnabled() {
RowButtonView("Inscription en ligne") {
navigation.path.append(Screen.settings)
@ -261,12 +261,12 @@ struct InscriptionManagerView: View {
}
}
}
.task(priority: .background) {
await _refreshList(forced: false)
}
.refreshable {
await _refreshList(forced: true)
}
// .task(priority: .background) {
// await _refreshList(forced: false)
// }
// .refreshable {
// await _refreshList(forced: true)
// }
.onAppear {
if tournament.enableOnlineRegistration == false || refreshStatus == true {
_setHash(currentSelectedSortedTeams: selectedSortedTeams)
@ -581,31 +581,31 @@ struct InscriptionManagerView: View {
// try? tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players)
// }
//
private func _refreshList(forced: Bool) async {
if refreshStatus == true, forced == false { return }
if tournament.enableOnlineRegistration == false { return }
if tournament.hasEnded() { return }
if tournament.refreshInProgress { return }
refreshResult = nil
refreshStatus = nil
do {
await self.tournament.refreshTeamList(forced: forced)
_setHash()
if let lastTeamRefresh = self.tournament.lastTeamRefresh?.formatted(date: .abbreviated, time: .shortened) {
self.refreshResult = "Dernière m-à-j : \(lastTeamRefresh)"
} else {
self.refreshResult = "La synchronization a réussi"
}
self.refreshStatus = true
} catch {
Logger.error(error)
self.refreshResult = "La synchronization a échoué"
self.refreshStatus = false
}
}
// private func _refreshList(forced: Bool) async {
// if refreshStatus == true, forced == false { return }
// if tournament.enableOnlineRegistration == false { return }
// if tournament.hasEnded() { return }
// if tournament.refreshInProgress { return }
//
// refreshResult = nil
// refreshStatus = nil
// do {
// await self.tournament.refreshTeamList(forced: forced)
//
// _setHash()
// if let lastTeamRefresh = self.tournament.lastTeamRefresh?.formatted(date: .abbreviated, time: .shortened) {
// self.refreshResult = "Dernière m-à-j : \(lastTeamRefresh)"
// } else {
// self.refreshResult = "La synchronization a réussi"
// }
// self.refreshStatus = true
//
// } catch {
// Logger.error(error)
// self.refreshResult = "La synchronization a échoué"
// self.refreshStatus = false
// }
// }
private func _teamRegisteredView(selectedSortedTeams: [TeamRegistration]) -> some View {
List {
@ -896,9 +896,9 @@ struct InscriptionManagerView: View {
}
}
RowButtonView("Rafraîchir les inscriptions en ligne") {
await _refreshList(forced: true)
}
// RowButtonView("Rafraîchir les inscriptions en ligne") {
// await _refreshList(forced: true)
// }
}
} header: {
HStack {

Loading…
Cancel
Save