diff --git a/PadelClub/Views/Cashier/Event/EventSettingsView.swift b/PadelClub/Views/Cashier/Event/EventSettingsView.swift index 97dfcd0..2b0492f 100644 --- a/PadelClub/Views/Cashier/Event/EventSettingsView.swift +++ b/PadelClub/Views/Cashier/Event/EventSettingsView.swift @@ -12,6 +12,7 @@ struct EventSettingsView: View { @EnvironmentObject var dataStore: DataStore @Bindable var event: Event @State private var eventName: String = "" + @FocusState private var textFieldIsFocus: Bool init(event: Event) { self.event = event @@ -21,17 +22,23 @@ struct EventSettingsView: View { var body: some View { Form { Section { - TextField("Nom de l'événement", text: $eventName) - .autocorrectionDisabled() - .keyboardType(.alphabet) - .onSubmit { - if eventName.trimmed.isEmpty == false { - event.name = eventName.trimmed - } else { - event.name = nil + ZStack { + Text(eventName).hidden() + TextEditor(text: $eventName) + .focused($textFieldIsFocus) + .autocorrectionDisabled() + .keyboardType(.alphabet) + .onSubmit { + if eventName.trimmed.isEmpty == false { + event.name = eventName.trimmed + } else { + event.name = nil + } + _save() } - _save() - } + } + } header: { + Text("Nom de l'événement") } footer: { if eventName.isEmpty == false { FooterButtonView("effacer le nom") { @@ -42,6 +49,19 @@ struct EventSettingsView: View { } } } + .toolbar { + ToolbarItemGroup(placement: .keyboard) { + if textFieldIsFocus { + Spacer() + Button { + textFieldIsFocus = false + } label: { + Text("Valider") + } + .buttonStyle(.bordered) + } + } + } } private func _save() { diff --git a/PadelClub/Views/Club/ClubDetailView.swift b/PadelClub/Views/Club/ClubDetailView.swift index d20ecf9..d74f0e0 100644 --- a/PadelClub/Views/Club/ClubDetailView.swift +++ b/PadelClub/Views/Club/ClubDetailView.swift @@ -31,23 +31,26 @@ struct ClubDetailView: View { var body: some View { Form { Section { - TextField("Nom du club", text: $club.name) - .autocorrectionDisabled() - .keyboardType(.alphabet) - .frame(maxWidth: .infinity) - .focused($focusedField, equals: ._name) - .submitLabel( displayContext == .addition ? .next : .done) - .onSubmit { - if club.acronym.isEmpty { - club.acronym = club.name.canonicalVersion.replaceCharactersFromSet(characterSet: .whitespacesAndNewlines) - focusedField = ._city - } - if displayContext == .addition { - focusedField = ._acronym + ZStack { + Text(club.name).hidden() + TextEditor(text: $club.name) + .autocorrectionDisabled() + .keyboardType(.alphabet) + .frame(maxWidth: .infinity) + .focused($focusedField, equals: ._name) + .submitLabel( displayContext == .addition ? .next : .done) + .onSubmit { + if club.acronym.isEmpty { + club.acronym = club.name.canonicalVersion.replaceCharactersFromSet(characterSet: .whitespacesAndNewlines) + focusedField = ._city + } + if displayContext == .addition { + focusedField = ._acronym + } } - } + } LabeledContent { - if acronymMode == .automatic { + if acronymMode == .automatic || displayContext == .lockedForEditing { Text(club.acronym) } else { TextField("Nom court", text: $club.acronym) @@ -82,6 +85,7 @@ struct ClubDetailView: View { } label: { Text(acronymMode.rawValue) } + .disabled(displayContext == .lockedForEditing) } } .onChange(of: acronymMode) { @@ -90,6 +94,8 @@ struct ClubDetailView: View { club.acronym = "" } } + } header: { + Text("Nom du club") } footer: { if displayContext == .lockedForEditing { Text("Édition impossible, vous n'êtes pas le créateur de ce club.").foregroundStyle(.logoRed) @@ -156,7 +162,7 @@ struct ClubDetailView: View { Text(club.city ?? "") } Link(destination: federalLink) { - Text("Fiche du club sur tenup") + Text("Voir la fiche du club sur tenup") } } } @@ -186,6 +192,21 @@ struct ClubDetailView: View { } } + if displayContext == .edition || displayContext == .lockedForEditing { + let isFavorite = club.isFavorite() + Section { + RowButtonView(isFavorite ? "Mettre en favori" : "Retirer des favoris", role: isFavorite ? nil : .destructive) { + if isFavorite { + dataStore.user.clubs.removeAll(where: { $0 == club.id }) + } else { + dataStore.user.clubs.append(club.id) + } + self.dataStore.saveUser() + } + } + } + + if displayContext == .edition { Section { RowButtonView("Supprimer ce club", role: .destructive) { @@ -206,20 +227,18 @@ struct ClubDetailView: View { .navigationTitle(displayContext == .addition ? "Nouveau club" : "Détail du club") .navigationBarTitleDisplayMode(.inline) .toolbar(.visible, for: .navigationBar) + .headerProminence(.increased) .toolbarBackground(.visible, for: .navigationBar) .toolbar { - if displayContext == .edition || displayContext == .lockedForEditing { - let isFavorite = club.isFavorite() - ToolbarItem(placement: .topBarTrailing) { - BarButtonView("Favori", icon: isFavorite ? "star.fill" : "star") { - if isFavorite { - dataStore.user.clubs.removeAll(where: { $0 == club.id }) - } else { - dataStore.user.clubs.append(club.id) - } - self.dataStore.saveUser() + ToolbarItemGroup(placement: .keyboard) { + if focusedField == ._name { + Spacer() + Button { + focusedField = nil + } label: { + Text("Valider") } - .tint(isFavorite ? .green : .logoRed) + .buttonStyle(.bordered) } } } diff --git a/PadelClub/Views/Club/ClubRowView.swift b/PadelClub/Views/Club/ClubRowView.swift index 05e89a2..3a3e2dc 100644 --- a/PadelClub/Views/Club/ClubRowView.swift +++ b/PadelClub/Views/Club/ClubRowView.swift @@ -13,10 +13,10 @@ struct ClubRowView: View { var body: some View { LabeledContent { - if displayContext == .edition { - Image(systemName: club.isFavorite() ? "star.fill" : "star") - .foregroundStyle(club.isFavorite() ? .green : .logoRed) - } +// if displayContext == .edition { +// Image(systemName: club.isFavorite() ? "star.fill" : "star") +// .foregroundStyle(club.isFavorite() ? .green : .logoRed) +// } } label: { Text(club.name) Text(club.acronym) diff --git a/PadelClub/Views/Event/EventCreationView.swift b/PadelClub/Views/Event/EventCreationView.swift index 802751d..2a88b9a 100644 --- a/PadelClub/Views/Event/EventCreationView.swift +++ b/PadelClub/Views/Event/EventCreationView.swift @@ -20,7 +20,8 @@ struct EventCreationView: View { @State private var eventName: String = "" @State var tournaments: [Tournament] = [] @State var selectedClub: Club? - + @FocusState private var textFieldIsFocus: Bool + let multiTournamentsEventTip = MultiTournamentsEventTip() var body: some View { @@ -63,9 +64,16 @@ struct EventCreationView: View { } } - TextField("Nom de l'événement", text: $eventName) - .autocorrectionDisabled() - .keyboardType(.alphabet) + VStack(alignment: .leading) { + Text("Nom de l'événement").font(.footnote) + ZStack { + Text(eventName).hidden() + TextEditor(text: $eventName) + .focused($textFieldIsFocus) + .autocorrectionDisabled() + .keyboardType(.alphabet) + } + } LabeledContent { Text(tournaments.count.formatted()) @@ -135,6 +143,19 @@ struct EventCreationView: View { } .popoverTip(multiTournamentsEventTip) } + + ToolbarItemGroup(placement: .keyboard) { + if textFieldIsFocus { + Spacer() + Button { + textFieldIsFocus = false + } label: { + Text("Valider") + } + .buttonStyle(.bordered) + } + } + } .navigationTitle("Nouvel événement") .navigationBarTitleDisplayMode(.inline) diff --git a/PadelClub/Views/Navigation/Ongoing/OngoingView.swift b/PadelClub/Views/Navigation/Ongoing/OngoingView.swift index 72e65be..7bcaed7 100644 --- a/PadelClub/Views/Navigation/Ongoing/OngoingView.swift +++ b/PadelClub/Views/Navigation/Ongoing/OngoingView.swift @@ -10,9 +10,13 @@ import SwiftUI struct OngoingView: View { @Environment(NavigationViewModel.self) private var navigation: NavigationViewModel @EnvironmentObject var dataStore: DataStore - + @State private var sortByField: Bool = false + let fieldSorting : [MySortDescriptor] = [.keyPath(\Match.courtIndex!), .keyPath(\Match.startDate!)] + let defaultSorting : [MySortDescriptor] = [.keyPath(\Match.startDate!), .keyPath(\Match.courtIndex!)] + var matches: [Match] { - dataStore.matches.filter({ $0.startDate != nil && $0.endDate == nil }).sorted(by: \.startDate!) + let sorting = sortByField ? fieldSorting : defaultSorting + return dataStore.matches.filter({ $0.startDate != nil && $0.endDate == nil && $0.courtIndex != nil }).sorted(using: sorting, order: .ascending) } var body: some View { @@ -54,10 +58,10 @@ struct OngoingView: View { .toolbar { ToolbarItem(placement: .topBarLeading) { Menu { - Button("Par terrain") { - - } - Button("Par date") { + Picker(selection: $sortByField) { + Text("Trier par date").tag(false) + Text("Trier par terrain").tag(true) + } label: { } //todo @@ -72,7 +76,7 @@ struct OngoingView: View { } ToolbarItem(placement: .status) { if matches.isEmpty == false { - Text("\(matches.count) matche" + matches.count.pluralSuffix) + Text("\(matches.count) match" + matches.count.pluralSuffix) } } } diff --git a/PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.swift b/PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.swift index 56997ce..2a3528d 100644 --- a/PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.swift +++ b/PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.swift @@ -63,8 +63,12 @@ struct TournamentGeneralSettingsView: View { .toolbar { if textFieldIsFocus { ToolbarItem(placement: .keyboard) { - Button("Valider") { - textFieldIsFocus = false + HStack { + Spacer() + Button("Valider") { + textFieldIsFocus = false + } + .buttonStyle(.bordered) } } }