|
|
|
@ -12,7 +12,17 @@ struct PlayerDetailView: View { |
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
@Bindable var player: PlayerRegistration |
|
|
|
@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 { |
|
|
|
var body: some View { |
|
|
|
Form { |
|
|
|
Form { |
|
|
|
@ -22,15 +32,21 @@ struct PlayerDetailView: View { |
|
|
|
.keyboardType(.alphabet) |
|
|
|
.keyboardType(.alphabet) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
|
|
|
|
.onSubmit(of: .text) { |
|
|
|
|
|
|
|
_save() |
|
|
|
|
|
|
|
} |
|
|
|
} label: { |
|
|
|
} label: { |
|
|
|
Text("Nom") |
|
|
|
Text("Nom") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LabeledContent { |
|
|
|
LabeledContent { |
|
|
|
TextField("Prénom", text: $player.firstName) |
|
|
|
TextField("Prénom", text: $player.firstName) |
|
|
|
.keyboardType(.alphabet) |
|
|
|
.keyboardType(.alphabet) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
|
|
|
|
.onSubmit(of: .text) { |
|
|
|
|
|
|
|
_save() |
|
|
|
|
|
|
|
} |
|
|
|
} label: { |
|
|
|
} label: { |
|
|
|
Text("Prénom") |
|
|
|
Text("Prénom") |
|
|
|
} |
|
|
|
} |
|
|
|
@ -44,7 +60,7 @@ struct PlayerDetailView: View { |
|
|
|
.keyboardType(.decimalPad) |
|
|
|
.keyboardType(.decimalPad) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.focused($textFieldIsFocus) |
|
|
|
.focused($focusedField, equals: ._rank) |
|
|
|
} label: { |
|
|
|
} label: { |
|
|
|
Text("Rang") |
|
|
|
Text("Rang") |
|
|
|
} |
|
|
|
} |
|
|
|
@ -69,7 +85,7 @@ struct PlayerDetailView: View { |
|
|
|
.keyboardType(.decimalPad) |
|
|
|
.keyboardType(.decimalPad) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.focused($textFieldIsFocus) |
|
|
|
.focused($focusedField, equals: ._computedRank) |
|
|
|
} label: { |
|
|
|
} label: { |
|
|
|
Text("Poids re-calculé") |
|
|
|
Text("Poids re-calculé") |
|
|
|
} |
|
|
|
} |
|
|
|
@ -79,17 +95,90 @@ struct PlayerDetailView: View { |
|
|
|
Text("Calculé en fonction du sexe") |
|
|
|
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) |
|
|
|
.scrollDismissesKeyboard(.immediately) |
|
|
|
.onChange(of: player.sex) { |
|
|
|
.onChange(of: player.hasArrived) { |
|
|
|
_save() |
|
|
|
_save() |
|
|
|
} |
|
|
|
} |
|
|
|
.onChange(of: player.computedRank) { |
|
|
|
.onChange(of: player.sex) { |
|
|
|
player.team()?.updateWeight(inTournamentCategory: tournament.tournamentCategory) |
|
|
|
|
|
|
|
_save() |
|
|
|
_save() |
|
|
|
} |
|
|
|
} |
|
|
|
.onChange(of: player.rank) { |
|
|
|
.onChange(of: player.computedRank) { |
|
|
|
player.setComputedRank(in: tournament) |
|
|
|
|
|
|
|
player.team()?.updateWeight(inTournamentCategory: tournament.tournamentCategory) |
|
|
|
player.team()?.updateWeight(inTournamentCategory: tournament.tournamentCategory) |
|
|
|
_save() |
|
|
|
_save() |
|
|
|
} |
|
|
|
} |
|
|
|
@ -100,7 +189,15 @@ struct PlayerDetailView: View { |
|
|
|
.toolbar { |
|
|
|
.toolbar { |
|
|
|
ToolbarItem(placement: .keyboard) { |
|
|
|
ToolbarItem(placement: .keyboard) { |
|
|
|
Button("Valider") { |
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|