parent
d34967df33
commit
b1db99f2a0
@ -0,0 +1,114 @@ |
|||||||
|
// |
||||||
|
// PlayerDetailView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 17/04/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
struct PlayerDetailView: View { |
||||||
|
@Environment(Tournament.self) var tournament: Tournament |
||||||
|
@EnvironmentObject var dataStore: DataStore |
||||||
|
@Bindable var player: PlayerRegistration |
||||||
|
@FocusState private var textFieldIsFocus: Bool |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
Form { |
||||||
|
Section { |
||||||
|
LabeledContent { |
||||||
|
TextField("Nom", text: $player.lastName) |
||||||
|
.keyboardType(.alphabet) |
||||||
|
.multilineTextAlignment(.trailing) |
||||||
|
.frame(maxWidth: .infinity) |
||||||
|
} label: { |
||||||
|
Text("Nom") |
||||||
|
} |
||||||
|
|
||||||
|
LabeledContent { |
||||||
|
TextField("Prénom", text: $player.firstName) |
||||||
|
.keyboardType(.alphabet) |
||||||
|
.multilineTextAlignment(.trailing) |
||||||
|
.frame(maxWidth: .infinity) |
||||||
|
} label: { |
||||||
|
Text("Prénom") |
||||||
|
} |
||||||
|
|
||||||
|
PlayerSexPickerView(player: player) |
||||||
|
} |
||||||
|
|
||||||
|
Section { |
||||||
|
LabeledContent { |
||||||
|
TextField("Rang", value: $player.rank, format: .number) |
||||||
|
.keyboardType(.decimalPad) |
||||||
|
.multilineTextAlignment(.trailing) |
||||||
|
.frame(maxWidth: .infinity) |
||||||
|
.focused($textFieldIsFocus) |
||||||
|
} label: { |
||||||
|
Text("Rang") |
||||||
|
} |
||||||
|
} header: { |
||||||
|
Text("Classement actuel") |
||||||
|
} |
||||||
|
|
||||||
|
if player.isMalePlayer() == false && tournament.tournamentCategory == .men, let rank = player.rank { |
||||||
|
Section { |
||||||
|
let value = PlayerRegistration.addon(for: rank, manMax: tournament.maleUnrankedValue ?? 0, womanMax: tournament.femaleUnrankedValue ?? 0) |
||||||
|
LabeledContent { |
||||||
|
Text(value.formatted()) |
||||||
|
} label: { |
||||||
|
Text("Valeur à rajouter") |
||||||
|
} |
||||||
|
LabeledContent { |
||||||
|
TextField("Rang", value: $player.weight, format: .number) |
||||||
|
.keyboardType(.decimalPad) |
||||||
|
.multilineTextAlignment(.trailing) |
||||||
|
.frame(maxWidth: .infinity) |
||||||
|
.focused($textFieldIsFocus) |
||||||
|
} label: { |
||||||
|
Text("Poids re-calculé") |
||||||
|
} |
||||||
|
} header: { |
||||||
|
Text("Ré-assimilation") |
||||||
|
} footer: { |
||||||
|
Text("Calculé en fonction du sexe") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.scrollDismissesKeyboard(.immediately) |
||||||
|
.onChange(of: player.sex) { |
||||||
|
_save() |
||||||
|
} |
||||||
|
.onChange(of: player.weight) { |
||||||
|
player.team()?.updateWeight() |
||||||
|
_save() |
||||||
|
} |
||||||
|
.onChange(of: player.rank) { |
||||||
|
player.setWeight(in: tournament) |
||||||
|
player.team()?.updateWeight() |
||||||
|
_save() |
||||||
|
} |
||||||
|
.headerProminence(.increased) |
||||||
|
.navigationTitle("Édition") |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
.toolbar { |
||||||
|
ToolbarItem(placement: .keyboard) { |
||||||
|
Button("Valider") { |
||||||
|
textFieldIsFocus = false |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private func _save() { |
||||||
|
try? dataStore.playerRegistrations.addOrUpdate(instance: player) |
||||||
|
if let team = player.team() { |
||||||
|
try? dataStore.teamRegistrations.addOrUpdate(instance: team) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
PlayerDetailView(player: PlayerRegistration.mock()) |
||||||
|
} |
||||||
@ -0,0 +1,45 @@ |
|||||||
|
// |
||||||
|
// EditingTeamView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Razmig Sarkissian on 17/04/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
struct EditingTeamView: View { |
||||||
|
@EnvironmentObject var dataStore: DataStore |
||||||
|
var team: TeamRegistration |
||||||
|
@State private var registrationDate : Date |
||||||
|
|
||||||
|
init(team: TeamRegistration) { |
||||||
|
self.team = team |
||||||
|
_registrationDate = State(wrappedValue: team.registrationDate ?? Date()) |
||||||
|
} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
List { |
||||||
|
Section { |
||||||
|
DatePicker(registrationDate.formatted(.dateTime.weekday()), selection: $registrationDate) |
||||||
|
} header: { |
||||||
|
Text("Date d'inscription") |
||||||
|
} |
||||||
|
} |
||||||
|
.onChange(of: registrationDate) { |
||||||
|
team.registrationDate = registrationDate |
||||||
|
_save() |
||||||
|
} |
||||||
|
.headerProminence(.increased) |
||||||
|
.navigationTitle("Édition") |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
} |
||||||
|
|
||||||
|
private func _save() { |
||||||
|
try? dataStore.teamRegistrations.addOrUpdate(instance: team) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
EditingTeamView(team: TeamRegistration.mock()) |
||||||
|
} |
||||||
Loading…
Reference in new issue