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

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

Loading…
Cancel
Save