|
|
|
@ -12,8 +12,9 @@ struct EventSettingsView: View { |
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
@Bindable var event: Event |
|
|
|
@Bindable var event: Event |
|
|
|
@State private var eventName: String = "" |
|
|
|
@State private var eventName: String = "" |
|
|
|
@FocusState private var textFieldIsFocus: Bool |
|
|
|
|
|
|
|
@State private var pageLink: PageLink = .teams |
|
|
|
@State private var pageLink: PageLink = .teams |
|
|
|
|
|
|
|
@State private var tournamentInformation: String = "" |
|
|
|
|
|
|
|
@FocusState private var focusedField: Tournament.CodingKeys? |
|
|
|
|
|
|
|
|
|
|
|
func eventLinksPasteData() -> String { |
|
|
|
func eventLinksPasteData() -> String { |
|
|
|
let tournaments = event.tournaments |
|
|
|
let tournaments = event.tournaments |
|
|
|
@ -41,6 +42,7 @@ struct EventSettingsView: View { |
|
|
|
init(event: Event) { |
|
|
|
init(event: Event) { |
|
|
|
self.event = event |
|
|
|
self.event = event |
|
|
|
_eventName = State(wrappedValue: event.name ?? "") |
|
|
|
_eventName = State(wrappedValue: event.name ?? "") |
|
|
|
|
|
|
|
_tournamentInformation = State(wrappedValue: event.tournaments.first?.information ?? "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
var body: some View { |
|
|
|
@ -51,7 +53,7 @@ struct EventSettingsView: View { |
|
|
|
.keyboardType(.alphabet) |
|
|
|
.keyboardType(.alphabet) |
|
|
|
.multilineTextAlignment(.leading) |
|
|
|
.multilineTextAlignment(.leading) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
.focused($textFieldIsFocus) |
|
|
|
.focused($focusedField, equals: ._name) |
|
|
|
} header: { |
|
|
|
} header: { |
|
|
|
Text("Nom de l'événement") |
|
|
|
Text("Nom de l'événement") |
|
|
|
} footer: { |
|
|
|
} footer: { |
|
|
|
@ -64,6 +66,39 @@ struct EventSettingsView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if event.tournaments.first?.dayDuration == 3, event.tournaments.count == 3 { |
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
RowButtonView("Répartir les tournois") { |
|
|
|
|
|
|
|
for (index, tournament) in event.tournaments.enumerated() { |
|
|
|
|
|
|
|
tournament.dayDuration = 1 |
|
|
|
|
|
|
|
tournament.startDate = Calendar.current.date(byAdding: .day, value: 1 + index, to: tournament.startDate)! |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_saveAllTournaments() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
ZStack { |
|
|
|
|
|
|
|
Text(tournamentInformation).opacity(0) |
|
|
|
|
|
|
|
Text(ContactType.defaultCustomMessage).opacity(0) |
|
|
|
|
|
|
|
TextEditor(text: $tournamentInformation) |
|
|
|
|
|
|
|
.keyboardType(.alphabet) |
|
|
|
|
|
|
|
.focused($focusedField, equals: ._information) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.frame(maxHeight: 200) |
|
|
|
|
|
|
|
.overlay { |
|
|
|
|
|
|
|
if tournamentInformation.isEmpty, focusedField != ._information { |
|
|
|
|
|
|
|
Text("Texte visible dans l'onglet informations sur Padel Club.").italic() |
|
|
|
|
|
|
|
.foregroundStyle(.secondary) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} header: { |
|
|
|
|
|
|
|
Text("Description d'un tournoi") |
|
|
|
|
|
|
|
} footer: { |
|
|
|
|
|
|
|
Text("Ce texte sera indiqué dans le champ information de tous les tournois de l'événement") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if event.club != nil { |
|
|
|
if event.club != nil { |
|
|
|
let eventLinksPasteData = eventLinksPasteData() |
|
|
|
let eventLinksPasteData = eventLinksPasteData() |
|
|
|
Section { |
|
|
|
Section { |
|
|
|
@ -87,42 +122,69 @@ struct EventSettingsView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.navigationBarBackButtonHidden(textFieldIsFocus) |
|
|
|
.navigationBarBackButtonHidden(focusedField != nil) |
|
|
|
.toolbar(content: { |
|
|
|
.toolbar(content: { |
|
|
|
if textFieldIsFocus { |
|
|
|
if focusedField != nil { |
|
|
|
ToolbarItem(placement: .topBarLeading) { |
|
|
|
ToolbarItem(placement: .topBarLeading) { |
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
textFieldIsFocus = false |
|
|
|
focusedField = nil |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
.toolbarBackground(.visible, for: .navigationBar) |
|
|
|
.toolbar { |
|
|
|
.toolbar { |
|
|
|
if textFieldIsFocus { |
|
|
|
if focusedField != nil { |
|
|
|
ToolbarItem(placement: .keyboard) { |
|
|
|
ToolbarItem(placement: .keyboard) { |
|
|
|
HStack { |
|
|
|
HStack { |
|
|
|
Spacer() |
|
|
|
if focusedField == ._name, eventName.isEmpty == false { |
|
|
|
Button("Valider") { |
|
|
|
Button("Effacer") { |
|
|
|
textFieldIsFocus = false |
|
|
|
|
|
|
|
if eventName.trimmed.isEmpty == false { |
|
|
|
|
|
|
|
event.name = eventName.prefixTrimmed(200) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
event.name = nil |
|
|
|
event.name = nil |
|
|
|
|
|
|
|
eventName = "" |
|
|
|
} |
|
|
|
} |
|
|
|
_save() |
|
|
|
.buttonStyle(.borderless) |
|
|
|
|
|
|
|
} else if focusedField == ._information, tournamentInformation.isEmpty == false { |
|
|
|
|
|
|
|
Button("Effacer") { |
|
|
|
|
|
|
|
tournamentInformation = "" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.buttonStyle(.borderless) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Spacer() |
|
|
|
|
|
|
|
Button("Valider") { |
|
|
|
|
|
|
|
focusedField = nil |
|
|
|
} |
|
|
|
} |
|
|
|
.buttonStyle(.bordered) |
|
|
|
.buttonStyle(.bordered) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.onChange(of: focusedField) { old, new in |
|
|
|
|
|
|
|
if old == ._name { |
|
|
|
|
|
|
|
let tournamentName = eventName.prefixMultilineTrimmed(200) |
|
|
|
|
|
|
|
if tournamentName.isEmpty { |
|
|
|
|
|
|
|
event.name = nil |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
event.name = eventName |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if old == ._information { |
|
|
|
|
|
|
|
tournamentInformation = tournamentInformation.prefixMultilineTrimmed(4000) |
|
|
|
|
|
|
|
_saveAllTournaments() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.onChange(of: event.name) { |
|
|
|
|
|
|
|
_save() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func _save() { |
|
|
|
private func _save() { |
|
|
|
do { |
|
|
|
dataStore.events.addOrUpdate(instance: event) |
|
|
|
try dataStore.events.addOrUpdate(instance: event) |
|
|
|
} |
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
private func _saveAllTournaments() { |
|
|
|
|
|
|
|
self.event.tournaments.forEach { tournament in |
|
|
|
|
|
|
|
tournament.information = tournamentInformation |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.dataStore.tournaments.addOrUpdate(contentOfs: self.event.tournaments) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|