parent
c0fb636621
commit
97e5d641fb
@ -0,0 +1,29 @@ |
|||||||
|
// |
||||||
|
// RoundView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 30/03/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
struct RoundView: View { |
||||||
|
var round: Round |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
List { |
||||||
|
ForEach(round.matches) { match in |
||||||
|
Section { |
||||||
|
MatchRowView(match: match, setupSeedContext: false, matchViewStyle: .sectionedStandardStyle) |
||||||
|
} header: { |
||||||
|
Text(match.matchTitle()) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.headerProminence(.increased) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
RoundView(round: Round.mock()) |
||||||
|
} |
||||||
@ -0,0 +1,80 @@ |
|||||||
|
// |
||||||
|
// RoundsView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 30/03/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
protocol Selectable { |
||||||
|
func selectionLabel() -> String |
||||||
|
} |
||||||
|
|
||||||
|
extension Round: Selectable { |
||||||
|
func selectionLabel() -> String { |
||||||
|
roundTitle() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct GenericDestinationPickerView<T: Identifiable & Selectable>: View { |
||||||
|
@Binding var selectedDestination: T? |
||||||
|
let destinations: [T] |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
ScrollView(.horizontal) { |
||||||
|
HStack { |
||||||
|
ForEach(destinations) { destination in |
||||||
|
Button { |
||||||
|
selectedDestination = destination |
||||||
|
} label: { |
||||||
|
Text(destination.selectionLabel()) |
||||||
|
} |
||||||
|
.padding() |
||||||
|
.background { |
||||||
|
Capsule() |
||||||
|
.fill(Color.white) |
||||||
|
.opacity(selectedDestination?.id == destination.id ? 1.0 : 0.5) |
||||||
|
} |
||||||
|
.buttonStyle(.plain) |
||||||
|
} |
||||||
|
} |
||||||
|
.fixedSize() |
||||||
|
.padding(8) |
||||||
|
} |
||||||
|
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) |
||||||
|
.background(Material.ultraThinMaterial) |
||||||
|
.overlay { |
||||||
|
VStack(spacing: 0) { |
||||||
|
Spacer() |
||||||
|
Divider() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct RoundsView: View { |
||||||
|
var tournament: Tournament |
||||||
|
@State private var selectedRound: Round? |
||||||
|
|
||||||
|
init(tournament: Tournament) { |
||||||
|
self.tournament = tournament |
||||||
|
_selectedRound = State(wrappedValue: tournament.getActiveRound()) |
||||||
|
} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
VStack(spacing: 0) { |
||||||
|
GenericDestinationPickerView(selectedDestination: $selectedRound, destinations: tournament.rounds()) |
||||||
|
if let selectedRound { |
||||||
|
RoundView(round: selectedRound) |
||||||
|
} |
||||||
|
} |
||||||
|
.navigationTitle(selectedRound?.roundTitle() ?? "") |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
RoundsView(tournament: Tournament.mock()) |
||||||
|
} |
||||||
Loading…
Reference in new issue