parent
91c4c5b591
commit
7b2989d29b
@ -0,0 +1,123 @@ |
|||||||
|
// |
||||||
|
// TeamRestingView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by razmig on 19/10/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
struct TeamRestingView: View { |
||||||
|
@Environment(Tournament.self) var tournament |
||||||
|
|
||||||
|
let readyMatches: [Match] |
||||||
|
let matchesLeft: [Match] |
||||||
|
|
||||||
|
@State private var sortingMode: SortingMode = .restingTime |
||||||
|
@State private var selectedCourt: Int? |
||||||
|
|
||||||
|
enum SortingMode: Int, Identifiable, CaseIterable { |
||||||
|
var id: Int { self.rawValue } |
||||||
|
case index |
||||||
|
case restingTime |
||||||
|
case court |
||||||
|
|
||||||
|
func localizedSortingModeLabel() -> String { |
||||||
|
switch self { |
||||||
|
case .index: |
||||||
|
return "Ordre" |
||||||
|
case .court: |
||||||
|
return "Terrain" |
||||||
|
case .restingTime: |
||||||
|
return "Repos" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var sortingModeCases: [SortingMode] { |
||||||
|
var sortingModes = [SortingMode]() |
||||||
|
sortingModes.append(.index) |
||||||
|
sortingModes.append(.restingTime) |
||||||
|
sortingModes.append(.court) |
||||||
|
return sortingModes |
||||||
|
} |
||||||
|
|
||||||
|
func contentUnavailableDescriptionLabel() -> String { |
||||||
|
switch sortingMode { |
||||||
|
case .index: |
||||||
|
return "Ce tournoi n'a aucun match prêt à démarrer" |
||||||
|
case .restingTime: |
||||||
|
return "Ce tournoi n'a aucun match prêt à démarrer" |
||||||
|
case .court: |
||||||
|
return "Ce tournoi n'a aucun match prêt à démarrer" |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var sortedMatches: [Match] { |
||||||
|
switch sortingMode { |
||||||
|
case .index: |
||||||
|
return readyMatches |
||||||
|
case .restingTime: |
||||||
|
return readyMatches.sorted(by: \.restingTimeForSorting) |
||||||
|
case .court: |
||||||
|
return readyMatches.sorted(using: [.keyPath(\.courtIndexForSorting), .keyPath(\.restingTimeForSorting)], order: .ascending) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
NavigationStack { |
||||||
|
List { |
||||||
|
Section { |
||||||
|
Picker(selection: $selectedCourt) { |
||||||
|
Text("Aucun").tag(nil as Int?) |
||||||
|
ForEach(0..<tournament.courtCount, id: \.self) { courtIndex in |
||||||
|
Text(tournament.courtName(atIndex: courtIndex)).tag(courtIndex as Int?) |
||||||
|
} |
||||||
|
} label: { |
||||||
|
Text("Sur le terrain") |
||||||
|
} |
||||||
|
// |
||||||
|
// Toggle(isOn: $checkCanPlay) { |
||||||
|
// if isFree { |
||||||
|
// Text("Vérifier le paiement ou la présence") |
||||||
|
// } else { |
||||||
|
// Text("Vérifier la présence") |
||||||
|
// } |
||||||
|
// } |
||||||
|
// } footer: { |
||||||
|
// if isFree { |
||||||
|
// Text("Masque les matchs où un ou plusieurs joueurs qui ne sont pas encore arrivé") |
||||||
|
// } else { |
||||||
|
// Text("Masque les matchs où un ou plusieurs joueurs n'ont pas encore réglé ou qui ne sont pas encore arrivé") |
||||||
|
// } |
||||||
|
} |
||||||
|
|
||||||
|
Section { |
||||||
|
if sortedMatches.isEmpty == false { |
||||||
|
ForEach(sortedMatches) { match in |
||||||
|
MatchRowView(match: match, matchViewStyle: .followUpStyle, updatedField: selectedCourt) |
||||||
|
} |
||||||
|
} else { |
||||||
|
ContentUnavailableView("Aucun match à venir", systemImage: "xmark.circle", description: Text(contentUnavailableDescriptionLabel())) |
||||||
|
} |
||||||
|
} header: { |
||||||
|
Picker(selection: $sortingMode) { |
||||||
|
ForEach(sortingModeCases) { sortingMode in |
||||||
|
Text(sortingMode.localizedSortingModeLabel()).tag(sortingMode) |
||||||
|
} |
||||||
|
} label: { |
||||||
|
Text("Méthode de tri") |
||||||
|
} |
||||||
|
.labelsHidden() |
||||||
|
.pickerStyle(.segmented) |
||||||
|
.fixedSize() |
||||||
|
} |
||||||
|
.headerProminence(.increased) |
||||||
|
.textCase(nil) |
||||||
|
} |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
.navigationTitle("Match à suivre") |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue