diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index ceaa9b3..48092f9 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -783,7 +783,7 @@ defer { let availableSeeds = seeds(inSeedGroup: availableSeedGroup) let availableSeedSpot = availableSeedSpot(inRoundIndex: roundIndex) let availableSeedOpponentSpot = availableSeedOpponentSpot(inRoundIndex: roundIndex) - let maxSpots = max(availableSeedSpot.count, availableSeedOpponentSpot.count) + let targetSpots = availableSeedSpot.isEmpty ? availableSeedOpponentSpot.count : availableSeedSpot.count if availableSeedGroup == SeedInterval(first: 3, last: 4), availableSeedSpot.count == 6 { return availableSeedGroup } @@ -796,18 +796,13 @@ defer { if let chunk = chunks.first(where: { seedInterval in return seedInterval.first == seededTeamsCount }) { - return seedGroupAvailable(atRoundIndex: roundIndex + 1, availableSeedGroup: chunk) - } else { + return seedGroupAvailable(atRoundIndex: roundIndex, availableSeedGroup: chunk) + } else if fullLeftSeeds.count > 1, targetSpots > 1, fullLeftSeeds.count >= targetSpots { let seeds = seeds() if let firstIndex = seeds.firstIndex(where: { $0.isSeedable() }) { - return SeedInterval(first: firstIndex + 1, last: firstIndex + maxSpots) + return seedGroupAvailable(atRoundIndex: roundIndex, availableSeedGroup: SeedInterval(first: firstIndex + 1, last: firstIndex + targetSpots)) } } - } else if fullLeftSeeds.count % maxSpots == 0 || fullLeftSeeds.count >= maxSpots { - let seeds = seeds() - if let firstIndex = seeds.firstIndex(where: { $0.isSeedable() }) { - return SeedInterval(first: firstIndex + 1, last: firstIndex + maxSpots) - } } } diff --git a/PadelClub/PadelClubApp.swift b/PadelClub/PadelClubApp.swift index 35e88fd..aed4326 100644 --- a/PadelClub/PadelClubApp.swift +++ b/PadelClub/PadelClubApp.swift @@ -106,7 +106,7 @@ struct PadelClubApp: App { } .task { - try? Tips.resetDatastore() +// try? Tips.resetDatastore() try? Tips.configure([ .displayFrequency(.immediate), diff --git a/PadelClub/Views/Round/RoundView.swift b/PadelClub/Views/Round/RoundView.swift index 343c330..3e94096 100644 --- a/PadelClub/Views/Round/RoundView.swift +++ b/PadelClub/Views/Round/RoundView.swift @@ -285,6 +285,12 @@ struct RoundView: View { seedSpaceLeft.isEmpty ? true : false } + private func _warnGroupWillCloseRound(availableSeedGroup: SeedInterval) -> Bool { + opposingSeeding + && seedSpaceLeft.count <= availableSeedGroup.count + && tournament.rounds().count - 1 > upperRound.round.index + } + private func _availableSeedSpot(availableSeedGroup: SeedInterval) -> [Match] { let spots = opposingSeeding ? spaceLeft : seedSpaceLeft if availableSeedGroup == SeedInterval(first: 3, last: 4), spots.count == 6 { @@ -379,8 +385,9 @@ struct RoundView: View { private func _seedGroupSection(availableSeeds: [TeamRegistration], availableSeedGroup: SeedInterval) -> some View { Group { + let warnGroupWillCloseRound = _warnGroupWillCloseRound(availableSeedGroup: availableSeedGroup) Section { - RowButtonView("Placer \(availableSeedGroup.localizedInterval())" + ((availableSeedGroup.isFixed() == false) ? " au hasard" : "")) { + RowButtonView("Placer \(availableSeedGroup.localizedInterval())" + ((availableSeedGroup.isFixed() == false) ? " au hasard" : ""), role: warnGroupWillCloseRound ? .destructive : nil, confirmationMessage: warnGroupWillCloseRound ? "Attention, tous vos matchs du tour précédent seront désactivés" : nil) { Task { tournament.setSeeds(inRoundIndex: upperRound.round.index, inSeedGroup: availableSeedGroup) _save(seeds: availableSeeds) @@ -408,7 +415,7 @@ struct RoundView: View { Text("Réalise un tirage des positions.") } } - RowButtonView("Tirage au sort \(availableSeedGroup.localizedInterval()) visuel") { + RowButtonView("Tirage au sort \(availableSeedGroup.localizedInterval()) visuel", role: warnGroupWillCloseRound ? .destructive : nil, confirmationMessage: warnGroupWillCloseRound ? "Attention, tous vos matchs du tour précédent seront désactivés" : nil) { self.selectedSeedGroup = availableSeedGroup } // if upperRound.round.index == 3, availableSeedGroup.first == 5, availableSeedGroup.last == 8, availableSeeds.count > 1, let half = availableSeedGroup.chunks()?.first { diff --git a/PadelClub/Views/Tournament/TournamentBuildView.swift b/PadelClub/Views/Tournament/TournamentBuildView.swift index 62b72c9..35c1a2c 100644 --- a/PadelClub/Views/Tournament/TournamentBuildView.swift +++ b/PadelClub/Views/Tournament/TournamentBuildView.swift @@ -130,10 +130,6 @@ struct TournamentBuildView: View { } } } - } else { - NavigationLink(value: Screen.restingTime) { - Text("Temps de repos") - } } if state == .running || state == .finished { TournamentInscriptionView(tournament: tournament) @@ -203,6 +199,12 @@ struct TournamentBuildView: View { cashierStatus = await tournament.cashierStatus() } } + + if state == .running { + NavigationLink(value: Screen.restingTime) { + Text("Temps de repos") + } + } } }