From c21d4688e3944804d9db31443c262f11a3e26547 Mon Sep 17 00:00:00 2001 From: Raz Date: Tue, 8 Oct 2024 14:45:55 +0200 Subject: [PATCH] fix seed removing not deleting team score add a refresh team button in groupestage setting view set tournament date start date when finishing a match before the set startdate --- PadelClub/Data/Match.swift | 12 +++++++++++- .../Components/GroupStageSettingsView.swift | 10 ++++++++++ PadelClub/Views/Match/MatchSetupView.swift | 10 ++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 7fee09c..548055c 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -546,7 +546,17 @@ defer { groupStageObject?.updateGroupStageState() roundObject?.updateTournamentState() - currentTournament()?.updateTournamentState() + if let tournament = currentTournament(), let endDate, let startDate { + if endDate.isEarlierThan(tournament.startDate) { + tournament.startDate = startDate + } + do { + try DataStore.shared.tournaments.addOrUpdate(instance: tournament) + } catch { + Logger.error(error) + } + tournament.updateTournamentState() + } updateFollowingMatchTeamScore() } diff --git a/PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift b/PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift index 64abb0f..84b529e 100644 --- a/PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift +++ b/PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift @@ -149,6 +149,16 @@ struct GroupStageSettingsView: View { Text("Tous les matchs seront recronstruits, les données des matchs seront perdus.") } + Section { + RowButtonView("Rafraichir", role: .destructive) { + let playedMatches = groupStage.playedMatches() + playedMatches.forEach { match in + match.updateTeamScores() + } + } + } footer: { + Text("Mets à jour les équipes de la poule si jamais une erreur est persistante.") + } } .onChange(of: size) { if size != groupStage.size { diff --git a/PadelClub/Views/Match/MatchSetupView.swift b/PadelClub/Views/Match/MatchSetupView.swift index 094dc80..ac777a6 100644 --- a/PadelClub/Views/Match/MatchSetupView.swift +++ b/PadelClub/Views/Match/MatchSetupView.swift @@ -190,15 +190,21 @@ struct MatchSetupView: View { func _removeTeam(team: TeamRegistration, teamPosition: TeamPosition) -> some View { Button(role: .cancel) { - //todo if match.isSeededBy(team: team, inTeamPosition: teamPosition) { + if let score = match.teamScore(ofTeam: team) { + do { + try tournamentStore.teamScores.delete(instance: score) + } catch { + Logger.error(error) + } + } + team.bracketPosition = nil do { try tournamentStore.teamRegistrations.addOrUpdate(instance: team) } catch { Logger.error(error) } - //match.updateTeamScores() match.previousMatches().forEach { previousMatch in if previousMatch.disabled { previousMatch.enableMatch()