From 83370f9e7363c9ee4965088592adb0328f9632f9 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Fri, 14 Mar 2025 19:28:40 +0100 Subject: [PATCH] fix issue with update ranking and mixte tournament --- PadelClub/Data/PlayerRegistration.swift | 2 +- PadelClub/Data/Tournament.swift | 8 +++++--- PadelClub/Views/Tournament/FileImportView.swift | 9 +++++++++ .../Views/Tournament/Screen/InscriptionManagerView.swift | 6 +++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/PadelClub/Data/PlayerRegistration.swift b/PadelClub/Data/PlayerRegistration.swift index 31358c8..31ed7a1 100644 --- a/PadelClub/Data/PlayerRegistration.swift +++ b/PadelClub/Data/PlayerRegistration.swift @@ -265,7 +265,7 @@ final class PlayerRegistration: ModelObject, Storable { } } - func updateRank(from sources: [CSVParser], lastRank: Int) async throws { + func updateRank(from sources: [CSVParser], lastRank: Int?) async throws { #if DEBUG_TIME let start = Date() defer { diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 13aa6ab..f104e3a 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1537,7 +1537,7 @@ defer { rankSourceDate = newDate // Fetch current month data only once - let monthData = currentMonthData() + var monthData = currentMonthData() if monthData == nil { async let lastRankWoman = SourceFileManager.shared.getUnrankValue(forMale: false, rankSourceDate: rankSourceDate) @@ -1554,10 +1554,12 @@ defer { } catch { Logger.error(error) } + + monthData = newMonthData } - let lastRankMan = monthData?.maleUnrankedValue ?? 0 - let lastRankWoman = monthData?.femaleUnrankedValue ?? 0 + let lastRankMan = monthData?.maleUnrankedValue + let lastRankWoman = monthData?.femaleUnrankedValue var chunkedParsers: [CSVParser] = [] if let providedSources { diff --git a/PadelClub/Views/Tournament/FileImportView.swift b/PadelClub/Views/Tournament/FileImportView.swift index 2a3549f..635cd78 100644 --- a/PadelClub/Views/Tournament/FileImportView.swift +++ b/PadelClub/Views/Tournament/FileImportView.swift @@ -499,7 +499,16 @@ struct FileImportView: View { private func _validate(tournament: Tournament) async { let filteredTeams = filteredTeams(tournament: tournament) + let lastDataSource: String? = DataStore.shared.appSettings.lastDataSource + var _mostRecentDateAvailable: Date? { + guard let lastDataSource else { return nil } + return URL.importDateFormatter.date(from: lastDataSource) + } + if let rankSourceDate = _mostRecentDateAvailable { + tournament.rankSourceDate = rankSourceDate + _save() + } tournament.importTeams(filteredTeams) validatedTournamentIds.insert(tournament.id) diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index d12fc78..b7608f9 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -278,6 +278,7 @@ struct InscriptionManagerView: View { } .sheet(isPresented: $presentImportView, onDismiss: { _setHash() + currentRankSourceDate = tournament.rankSourceDate }) { NavigationStack { FileImportView(defaultFileProvider: tournament.isAnimation() ? .custom : .frenchFederation) @@ -293,8 +294,11 @@ struct InscriptionManagerView: View { _setHash() } .onChange(of: currentRankSourceDate) { - if let currentRankSourceDate, tournament.rankSourceDate != currentRankSourceDate { + if let currentRankSourceDate, tournament.rankSourceDate != currentRankSourceDate, unsortedPlayers.isEmpty == false { confirmUpdateRank = true + } else { + tournament.rankSourceDate = currentRankSourceDate + _save() } } .sheet(isPresented: $confirmUpdateRank, onDismiss: {