From b41e8064d7771eb1a197da835becd8c5c3852c7c Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Tue, 14 Oct 2025 11:35:18 +0200 Subject: [PATCH] some fixes --- .../Views/Calling/BracketCallingView.swift | 2 +- .../CallMessageCustomizationView.swift | 1 - PadelClub/Views/Planning/PlanningView.swift | 52 +++++++++++++------ .../Screen/TableStructureView.swift | 21 +++++++- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/PadelClub/Views/Calling/BracketCallingView.swift b/PadelClub/Views/Calling/BracketCallingView.swift index 50e1583..e203388 100644 --- a/PadelClub/Views/Calling/BracketCallingView.swift +++ b/PadelClub/Views/Calling/BracketCallingView.swift @@ -106,7 +106,7 @@ struct BracketCallingView: View { ForEach(filteredRounds()) { round in let seeds = seeds(forRoundIndex: round.index) - let startDate = round.startDate ?? round.playedMatches().first?.startDate + let startDate = ([round.startDate] + round.playedMatches().map { $0.startDate }).compacted().min() let callSeeds = seeds.filter({ tournament.isStartDateIsDifferentThanCallDate($0, expectedSummonDate: startDate) == false }) if seeds.isEmpty == false { Section { diff --git a/PadelClub/Views/Calling/CallMessageCustomizationView.swift b/PadelClub/Views/Calling/CallMessageCustomizationView.swift index 0ef3dfb..1c9c7ef 100644 --- a/PadelClub/Views/Calling/CallMessageCustomizationView.swift +++ b/PadelClub/Views/Calling/CallMessageCustomizationView.swift @@ -236,7 +236,6 @@ struct CallMessageCustomizationView: View { let hasBeenCreated: Bool = eventClub.hasBeenCreated(by: StoreCenter.main.userId) Section { TextField("Nom du club", text: $customClubName, axis: .vertical) - .lineLimit(2) .autocorrectionDisabled() .focused($focusedField, equals: .clubName) .onSubmit { diff --git a/PadelClub/Views/Planning/PlanningView.swift b/PadelClub/Views/Planning/PlanningView.swift index c4fe24e..b2afebe 100644 --- a/PadelClub/Views/Planning/PlanningView.swift +++ b/PadelClub/Views/Planning/PlanningView.swift @@ -728,9 +728,6 @@ struct PlanningView: View { } } - private func _eventCourtCount() -> Int { timeSlots.first?.value.first?.currentTournament()?.eventObject()?.eventCourtCount() ?? 2 - } - private func _save() { let groupByTournaments = allMatches.grouped { match in match.currentTournament() @@ -749,16 +746,27 @@ struct PlanningView: View { Button("Tirer au sort") { _removeCourts() - - let eventCourtCount = _eventCourtCount() - + for slot in timeSlots { - var courtsAvailable = Array(0...eventCourtCount) let matches = slot.value - matches.forEach { match in - if let rand = courtsAvailable.randomElement() { + var courtsByTournament: [String: Set] = [:] + for match in matches { + if let tournament = match.currentTournament(), + let available = tournament.matchScheduler()?.courtsAvailable { + courtsByTournament[tournament.id, default: []].formUnion(available) + } + } + + for match in matches { + guard let tournament = match.currentTournament() else { continue } + // Get current set of available courts for this tournament id + guard var courts = courtsByTournament[tournament.id], !courts.isEmpty else { continue } + // Pick a random court + if let rand = courts.randomElement() { match.courtIndex = rand - courtsAvailable.remove(elements: [rand]) + // Remove from local copy and assign back into the dictionary + courts.remove(rand) + courtsByTournament[tournament.id] = courts } } } @@ -768,16 +776,27 @@ struct PlanningView: View { Button("Fixer par ordre croissant") { _removeCourts() - - let eventCourtCount = _eventCourtCount() - + for slot in timeSlots { - var courtsAvailable = Array(0..] = [:] + for match in matches { + if let tournament = match.currentTournament(), + let available = tournament.matchScheduler()?.courtsAvailable { + courtsByTournament[tournament.id, default: []].formUnion(available.sorted()) + } + } + for i in 0..