parent
ff0b236afc
commit
db9d4637d0
@ -0,0 +1,53 @@ |
|||||||
|
// |
||||||
|
// 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.matches) { match in |
||||||
|
MatchRowView(match: match, matchViewStyle: .standardStyle) |
||||||
|
} |
||||||
|
} header: { |
||||||
|
Text(loserRound.roundTitle()) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
LoserBracketView(loserRounds: [Round.mock()]) |
||||||
|
.environmentObject(DataStore.shared) |
||||||
|
} |
||||||
@ -0,0 +1,65 @@ |
|||||||
|
// |
||||||
|
// LoserRoundsView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 04/04/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
extension Int: Selectable, Identifiable { |
||||||
|
public var id: Int { self } |
||||||
|
func selectionLabel() -> String { |
||||||
|
"Tour #\(self + 1)" |
||||||
|
} |
||||||
|
|
||||||
|
func badgeValue() -> Int? { |
||||||
|
nil |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct LoserRoundsView: View { |
||||||
|
var upperBracketRound: Round |
||||||
|
@State private var selectedRound: Round? |
||||||
|
let loserRounds: [Round] |
||||||
|
|
||||||
|
init(upperBracketRound: Round) { |
||||||
|
self.upperBracketRound = upperBracketRound |
||||||
|
self.loserRounds = upperBracketRound.loserRounds() |
||||||
|
_selectedRound = State(wrappedValue: upperBracketRound.getActiveLoserRound()) |
||||||
|
} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
VStack(spacing: 0) { |
||||||
|
GenericDestinationPickerView(selectedDestination: $selectedRound, destinations: loserRounds, nilDestinationIsValid: true) |
||||||
|
switch selectedRound { |
||||||
|
case .none: |
||||||
|
List { |
||||||
|
} |
||||||
|
case .some(let selectedRound): |
||||||
|
LoserRoundView(loserRounds: upperBracketRound.loserRounds(forRoundIndex: selectedRound.index)) |
||||||
|
} |
||||||
|
} |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct LoserRoundView: View { |
||||||
|
let loserRounds: [Round] |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
List { |
||||||
|
ForEach(loserRounds) { loserRound in |
||||||
|
Section { |
||||||
|
ForEach(loserRound.matches) { match in |
||||||
|
MatchRowView(match: match, matchViewStyle: .sectionedStandardStyle) |
||||||
|
} |
||||||
|
} header: { |
||||||
|
Text(loserRound.roundTitle(.wide)) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.headerProminence(.increased) |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue