parent
df56b384e0
commit
38d05af6df
@ -1,53 +0,0 @@ |
||||
// |
||||
// LoserBracketView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 04/04/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct LoserBracketView: View { |
||||
@EnvironmentObject var dataStore: DataStore |
||||
let loserRounds: [Round] |
||||
|
||||
@ViewBuilder |
||||
var body: some View { |
||||
if let first = loserRounds.first { |
||||
List { |
||||
ForEach(loserRounds) { loserRound in |
||||
_loserRoundView(loserRound) |
||||
let childLoserRounds = loserRound.loserRounds() |
||||
if childLoserRounds.isEmpty == false { |
||||
let uniqueChildRound = childLoserRounds.first |
||||
if childLoserRounds.count == 1, let uniqueChildRound { |
||||
_loserRoundView(uniqueChildRound) |
||||
} else if let uniqueChildRound { |
||||
NavigationLink { |
||||
LoserBracketView(loserRounds: childLoserRounds) |
||||
} label: { |
||||
Text(uniqueChildRound.roundTitle()) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
.navigationTitle(first.roundTitle()) |
||||
} |
||||
} |
||||
|
||||
private func _loserRoundView(_ loserRound: Round) -> some View { |
||||
Section { |
||||
ForEach(loserRound.playedMatches()) { match in |
||||
MatchRowView(match: match, matchViewStyle: .standardStyle) |
||||
} |
||||
} header: { |
||||
Text(loserRound.roundTitle()) |
||||
} |
||||
} |
||||
} |
||||
|
||||
#Preview { |
||||
LoserBracketView(loserRounds: [Round.mock()]) |
||||
.environmentObject(DataStore.shared) |
||||
} |
||||
@ -0,0 +1,72 @@ |
||||
// |
||||
// LoserRoundView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 04/04/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
struct LoserRoundView: View { |
||||
@EnvironmentObject var dataStore: DataStore |
||||
let loserRounds: [Round] |
||||
@State private var isEditingTournamentSeed: Bool = false |
||||
|
||||
private func _roundDisabled() -> Bool { |
||||
loserRounds.allSatisfy({ $0.isDisabled() }) |
||||
} |
||||
|
||||
var body: some View { |
||||
List { |
||||
if isEditingTournamentSeed == true { |
||||
_editingView() |
||||
} |
||||
|
||||
ForEach(loserRounds) { loserRound in |
||||
if isEditingTournamentSeed || loserRound.isDisabled() == false { |
||||
Section { |
||||
let matches = isEditingTournamentSeed ? loserRound.playedMatches() : loserRound.playedMatches().filter({ $0.disabled == false }) |
||||
ForEach(matches) { match in |
||||
MatchRowView(match: match, matchViewStyle: .standardStyle) |
||||
.overlay { |
||||
if match.disabled && isEditingTournamentSeed { |
||||
Image(systemName: "xmark") |
||||
.resizable() |
||||
.scaledToFit() |
||||
.opacity(0.8) |
||||
} |
||||
} |
||||
.disabled(match.disabled) |
||||
} |
||||
} header: { |
||||
Text(loserRound.roundTitle(.wide)) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
.headerProminence(.increased) |
||||
.toolbar { |
||||
ToolbarItem(placement: .topBarTrailing) { |
||||
Button(isEditingTournamentSeed == true ? "Valider" : "Modifier") { |
||||
isEditingTournamentSeed.toggle() |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private func _editingView() -> some View { |
||||
if _roundDisabled() { |
||||
RowButtonView("Jouer ce tour", role: .destructive) { |
||||
loserRounds.forEach { round in |
||||
round.enableRound() |
||||
} |
||||
} |
||||
} else { |
||||
RowButtonView("Ne pas jouer ce tour", role: .destructive) { |
||||
loserRounds.forEach { round in |
||||
round.disableRound() |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue