From 8a1d59ac2e66887e1a11b415ec3858753afe6284 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Fri, 14 Jun 2024 09:59:01 +0200 Subject: [PATCH] fix stuff --- PadelClub/Views/Player/PlayerDetailView.swift | 117 ++++++++++++++++-- PadelClub/Views/Team/EditingTeamView.swift | 26 ++++ PadelClub/Views/Team/TeamDetailView.swift | 1 + .../Screen/InscriptionManagerView.swift | 5 - 4 files changed, 134 insertions(+), 15 deletions(-) diff --git a/PadelClub/Views/Player/PlayerDetailView.swift b/PadelClub/Views/Player/PlayerDetailView.swift index 33d8f00..24687d0 100644 --- a/PadelClub/Views/Player/PlayerDetailView.swift +++ b/PadelClub/Views/Player/PlayerDetailView.swift @@ -12,7 +12,17 @@ struct PlayerDetailView: View { @Environment(Tournament.self) var tournament: Tournament @EnvironmentObject var dataStore: DataStore @Bindable var player: PlayerRegistration - @FocusState private var textFieldIsFocus: Bool + @State private var licenceId: String + @State private var phoneNumber: String + @State private var email: String + @FocusState var focusedField: PlayerRegistration.CodingKeys? + + init(player: PlayerRegistration) { + self.player = player + _licenceId = .init(wrappedValue: player.licenceId ?? "") + _email = .init(wrappedValue: player.email ?? "") + _phoneNumber = .init(wrappedValue: player.phoneNumber ?? "") + } var body: some View { Form { @@ -22,15 +32,21 @@ struct PlayerDetailView: View { .keyboardType(.alphabet) .multilineTextAlignment(.trailing) .frame(maxWidth: .infinity) + .onSubmit(of: .text) { + _save() + } } label: { Text("Nom") } - + LabeledContent { TextField("Prénom", text: $player.firstName) .keyboardType(.alphabet) .multilineTextAlignment(.trailing) .frame(maxWidth: .infinity) + .onSubmit(of: .text) { + _save() + } } label: { Text("Prénom") } @@ -44,7 +60,7 @@ struct PlayerDetailView: View { .keyboardType(.decimalPad) .multilineTextAlignment(.trailing) .frame(maxWidth: .infinity) - .focused($textFieldIsFocus) + .focused($focusedField, equals: ._rank) } label: { Text("Rang") } @@ -69,7 +85,7 @@ struct PlayerDetailView: View { .keyboardType(.decimalPad) .multilineTextAlignment(.trailing) .frame(maxWidth: .infinity) - .focused($textFieldIsFocus) + .focused($focusedField, equals: ._computedRank) } label: { Text("Poids re-calculé") } @@ -79,17 +95,90 @@ struct PlayerDetailView: View { Text("Calculé en fonction du sexe") } } + + Section { + Toggle("Joueur sur place", isOn: $player.hasArrived) + } + + Section { + LabeledContent { + TextField("Licence", text: $licenceId) + .keyboardType(.alphabet) + .multilineTextAlignment(.trailing) + .autocorrectionDisabled() + .frame(maxWidth: .infinity) + .onSubmit(of: .text) { + player.licenceId = licenceId + _save() + } + } label: { + Text("Licence") + } + + RowButtonView("Copier dans le presse-papier") { + let pasteboard = UIPasteboard.general + pasteboard.string = player.licenceId?.strippedLicense + } + } + + Section { + LabeledContent { + TextField("Téléphone", text: $phoneNumber) + .keyboardType(.namePhonePad) + .multilineTextAlignment(.trailing) + .autocorrectionDisabled() + .frame(maxWidth: .infinity) + .onSubmit(of: .text) { + player.phoneNumber = phoneNumber + _save() + } + } label: { + Text("Téléphone") + } + + RowButtonView("Copier dans le presse-papier") { + let pasteboard = UIPasteboard.general + pasteboard.string = player.phoneNumber + } + } + + Section { + LabeledContent { + TextField("Email", text: $email) + .keyboardType(.emailAddress) + .multilineTextAlignment(.trailing) + .autocorrectionDisabled() + .frame(maxWidth: .infinity) + .onSubmit(of: .text) { + player.email = email + _save() + } + } label: { + Text("Email") + } + + RowButtonView("Copier dans le presse-papier") { + let pasteboard = UIPasteboard.general + pasteboard.string = player.email + } + } + + } + .toolbar { + ToolbarItem(placement: .topBarTrailing) { + ShareLink(item: player.pasteData()) { + Label("Partagez", systemImage: "square.and.arrow.up") + } + } } .scrollDismissesKeyboard(.immediately) - .onChange(of: player.sex) { + .onChange(of: player.hasArrived) { _save() } - .onChange(of: player.computedRank) { - player.team()?.updateWeight(inTournamentCategory: tournament.tournamentCategory) + .onChange(of: player.sex) { _save() } - .onChange(of: player.rank) { - player.setComputedRank(in: tournament) + .onChange(of: player.computedRank) { player.team()?.updateWeight(inTournamentCategory: tournament.tournamentCategory) _save() } @@ -100,7 +189,15 @@ struct PlayerDetailView: View { .toolbar { ToolbarItem(placement: .keyboard) { Button("Valider") { - textFieldIsFocus = false + if focusedField == ._rank { + player.setComputedRank(in: tournament) + player.team()?.updateWeight(inTournamentCategory: tournament.tournamentCategory) + _save() + } else if focusedField == ._computedRank { + player.team()?.updateWeight(inTournamentCategory: tournament.tournamentCategory) + _save() + } + focusedField = nil } } } diff --git a/PadelClub/Views/Team/EditingTeamView.swift b/PadelClub/Views/Team/EditingTeamView.swift index 0612876..e63f725 100644 --- a/PadelClub/Views/Team/EditingTeamView.swift +++ b/PadelClub/Views/Team/EditingTeamView.swift @@ -46,6 +46,17 @@ struct EditingTeamView: View { Text("Date d'inscription") } + Section { + Toggle(isOn: hasArrived) { + Text("Équipe sur place") + } + /* + Toggle(isOn: $team.confirmedCall) { + Text("Équipe sur place") + } + */ + } + Section { RowButtonView("Retirer des poules", role: .destructive) { team.resetGroupeStagePosition() @@ -72,6 +83,21 @@ struct EditingTeamView: View { .toolbarBackground(.visible, for: .navigationBar) } + private var hasArrived: Binding { + Binding { + team.unsortedPlayers().allSatisfy({ $0.hasArrived }) + } set: { hasArrived in + team.unsortedPlayers().forEach { + $0.hasArrived = hasArrived + } + do { + try dataStore.playerRegistrations.addOrUpdate(contentOfs: team.unsortedPlayers()) + } catch { + Logger.error(error) + } + } + + } private func _save() { do { try dataStore.teamRegistrations.addOrUpdate(instance: team) diff --git a/PadelClub/Views/Team/TeamDetailView.swift b/PadelClub/Views/Team/TeamDetailView.swift index 2131e41..889341c 100644 --- a/PadelClub/Views/Team/TeamDetailView.swift +++ b/PadelClub/Views/Team/TeamDetailView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import LeStorage struct TeamDetailView: View { @Environment(Tournament.self) var tournament: Tournament diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index 16d463b..7c8172e 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -533,11 +533,6 @@ struct InscriptionManagerView: View { let teamIndex = team.index(in: sortedTeams) Section { TeamDetailView(team: team) - .contextMenu { - Button("équipe présente") { - team.hasArrived() - } - } } header: { TeamHeaderView(team: team, teamIndex: teamIndex, tournament: tournament) } footer: {