parent
c025559b5e
commit
ac60d64acc
@ -0,0 +1,133 @@ |
|||||||
|
// |
||||||
|
// FollowUpMatchView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by razmig on 11/10/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
struct FollowUpMatchView: View { |
||||||
|
@EnvironmentObject var dataStore: DataStore |
||||||
|
@Environment(\.dismiss) private var dismiss |
||||||
|
let match: Match |
||||||
|
let readyMatches: [Match] |
||||||
|
let isFree: Bool |
||||||
|
|
||||||
|
@State private var sortingMode: SortingMode = .index |
||||||
|
@State private var selectedCourt: Int? |
||||||
|
@State private var checkCanPlay: Bool = false |
||||||
|
@Binding var dismissWhenPresentFollowUpMatchIsDismissed: Bool |
||||||
|
|
||||||
|
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 "Temps de repos" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
init(match: Match, dismissWhenPresentFollowUpMatchIsDismissed: Binding<Bool>) { |
||||||
|
_dismissWhenPresentFollowUpMatchIsDismissed = dismissWhenPresentFollowUpMatchIsDismissed |
||||||
|
self.match = match |
||||||
|
_selectedCourt = .init(wrappedValue: match.courtIndex) |
||||||
|
let currentTournament = match.currentTournament() |
||||||
|
let allMatches = currentTournament?.allMatches() ?? [] |
||||||
|
let runningMatches = currentTournament?.runningMatches(allMatches) ?? [] |
||||||
|
let readyMatches = currentTournament?.readyMatches(allMatches) ?? [] |
||||||
|
self.readyMatches = currentTournament?.availableToStart(readyMatches, in: runningMatches, checkCanPlay: false) ?? [] |
||||||
|
self.isFree = currentTournament?.isFree() ?? true |
||||||
|
} |
||||||
|
|
||||||
|
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?) |
||||||
|
if let tournament = match.currentTournament() { |
||||||
|
ForEach(0..<tournament.courtCount, id: \.self) { courtIndex in |
||||||
|
Text(tournament.courtName(atIndex: courtIndex)).tag(courtIndex as Int?) |
||||||
|
} |
||||||
|
} else { |
||||||
|
ForEach(0..<20, id: \.self) { courtIndex in |
||||||
|
Text(Court.courtIndexedTitle(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 { |
||||||
|
ForEach(sortedMatches) { match in |
||||||
|
MatchRowView(match: match, matchViewStyle: .followUpStyle, updatedField: selectedCourt) |
||||||
|
} |
||||||
|
} header: { |
||||||
|
Picker(selection: $sortingMode) { |
||||||
|
ForEach(SortingMode.allCases) { 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) |
||||||
|
.toolbar { |
||||||
|
ToolbarItem(placement: .topBarLeading) { |
||||||
|
Button("Retour", role: .cancel) { |
||||||
|
dismiss() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.onChange(of: readyMatches) { |
||||||
|
dismissWhenPresentFollowUpMatchIsDismissed = true |
||||||
|
dismiss() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue