fix issue with auto structure

main
Razmig Sarkissian 2 weeks ago
parent b287b67a0c
commit a5445e7280
  1. 15
      PadelClub/Views/Tournament/Screen/TableStructureView.swift

@ -238,6 +238,8 @@ struct TableStructureView: View {
}
}
if selectedTournament == nil {
Section {
if groupStageCount > 0 {
if structurePreset != .doubleGroupStage {
@ -326,7 +328,7 @@ struct TableStructureView: View {
Text("Vous pourrez ensuite modifier le nombre de tour dans l'écran de réglages du tableau.")
}
}
}
if tournament.state() != .initial {
if seedRepartition.isEmpty == false {
@ -661,7 +663,7 @@ struct TableStructureView: View {
tournament.tournamentStore?.matches.addOrUpdate(contentOfs: tournament._allMatchesIncludingDisabled())
}
if seedRepartition.count > 0 {
if seedRepartition.count > 0, selectedTournament == nil {
await _handleSeedRepartition()
}
} else if (rebuildEverything == false && requirements.contains(.groupStage)) {
@ -683,13 +685,16 @@ struct TableStructureView: View {
}
private func _handleSeedRepartition() async {
while tournament.rounds().count < seedRepartition.count {
await tournament.addNewRound(tournament.rounds().count)
let rounds = tournament.rounds()
var roundsCount = rounds.count
while roundsCount < seedRepartition.count {
await tournament.addNewRound(roundsCount)
roundsCount += 1
}
if seedRepartition.reduce(0, +) > 0 {
let rounds = tournament.rounds()
let roundsToDelete = rounds.suffix(rounds.count - seedRepartition.count)
let roundsToDelete = rounds.prefix(rounds.count - seedRepartition.count)
for round in roundsToDelete {
await tournament.removeRound(round)
}

Loading…
Cancel
Save