fix club stuff

multistore
Razmig Sarkissian 1 year ago
parent eb7acc1299
commit 15bb8f879a
  1. 40
      PadelClub/Views/Cashier/Event/EventSettingsView.swift
  2. 73
      PadelClub/Views/Club/ClubDetailView.swift
  3. 8
      PadelClub/Views/Club/ClubRowView.swift
  4. 29
      PadelClub/Views/Event/EventCreationView.swift
  5. 18
      PadelClub/Views/Navigation/Ongoing/OngoingView.swift
  6. 8
      PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.swift

@ -12,6 +12,7 @@ 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
init(event: Event) { init(event: Event) {
self.event = event self.event = event
@ -21,17 +22,23 @@ struct EventSettingsView: View {
var body: some View { var body: some View {
Form { Form {
Section { Section {
TextField("Nom de l'événement", text: $eventName) ZStack {
.autocorrectionDisabled() Text(eventName).hidden()
.keyboardType(.alphabet) TextEditor(text: $eventName)
.onSubmit { .focused($textFieldIsFocus)
if eventName.trimmed.isEmpty == false { .autocorrectionDisabled()
event.name = eventName.trimmed .keyboardType(.alphabet)
} else { .onSubmit {
event.name = nil if eventName.trimmed.isEmpty == false {
event.name = eventName.trimmed
} else {
event.name = nil
}
_save()
} }
_save() }
} } header: {
Text("Nom de l'événement")
} footer: { } footer: {
if eventName.isEmpty == false { if eventName.isEmpty == false {
FooterButtonView("effacer le nom") { 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() { private func _save() {

@ -31,23 +31,26 @@ struct ClubDetailView: View {
var body: some View { var body: some View {
Form { Form {
Section { Section {
TextField("Nom du club", text: $club.name) ZStack {
.autocorrectionDisabled() Text(club.name).hidden()
.keyboardType(.alphabet) TextEditor(text: $club.name)
.frame(maxWidth: .infinity) .autocorrectionDisabled()
.focused($focusedField, equals: ._name) .keyboardType(.alphabet)
.submitLabel( displayContext == .addition ? .next : .done) .frame(maxWidth: .infinity)
.onSubmit { .focused($focusedField, equals: ._name)
if club.acronym.isEmpty { .submitLabel( displayContext == .addition ? .next : .done)
club.acronym = club.name.canonicalVersion.replaceCharactersFromSet(characterSet: .whitespacesAndNewlines) .onSubmit {
focusedField = ._city if club.acronym.isEmpty {
} club.acronym = club.name.canonicalVersion.replaceCharactersFromSet(characterSet: .whitespacesAndNewlines)
if displayContext == .addition { focusedField = ._city
focusedField = ._acronym }
if displayContext == .addition {
focusedField = ._acronym
}
} }
} }
LabeledContent { LabeledContent {
if acronymMode == .automatic { if acronymMode == .automatic || displayContext == .lockedForEditing {
Text(club.acronym) Text(club.acronym)
} else { } else {
TextField("Nom court", text: $club.acronym) TextField("Nom court", text: $club.acronym)
@ -82,6 +85,7 @@ struct ClubDetailView: View {
} label: { } label: {
Text(acronymMode.rawValue) Text(acronymMode.rawValue)
} }
.disabled(displayContext == .lockedForEditing)
} }
} }
.onChange(of: acronymMode) { .onChange(of: acronymMode) {
@ -90,6 +94,8 @@ struct ClubDetailView: View {
club.acronym = "" club.acronym = ""
} }
} }
} header: {
Text("Nom du club")
} footer: { } footer: {
if displayContext == .lockedForEditing { if displayContext == .lockedForEditing {
Text("Édition impossible, vous n'êtes pas le créateur de ce club.").foregroundStyle(.logoRed) 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 ?? "") Text(club.city ?? "")
} }
Link(destination: federalLink) { 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 { if displayContext == .edition {
Section { Section {
RowButtonView("Supprimer ce club", role: .destructive) { RowButtonView("Supprimer ce club", role: .destructive) {
@ -206,20 +227,18 @@ struct ClubDetailView: View {
.navigationTitle(displayContext == .addition ? "Nouveau club" : "Détail du club") .navigationTitle(displayContext == .addition ? "Nouveau club" : "Détail du club")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbar(.visible, for: .navigationBar) .toolbar(.visible, for: .navigationBar)
.headerProminence(.increased)
.toolbarBackground(.visible, for: .navigationBar) .toolbarBackground(.visible, for: .navigationBar)
.toolbar { .toolbar {
if displayContext == .edition || displayContext == .lockedForEditing { ToolbarItemGroup(placement: .keyboard) {
let isFavorite = club.isFavorite() if focusedField == ._name {
ToolbarItem(placement: .topBarTrailing) { Spacer()
BarButtonView("Favori", icon: isFavorite ? "star.fill" : "star") { Button {
if isFavorite { focusedField = nil
dataStore.user.clubs.removeAll(where: { $0 == club.id }) } label: {
} else { Text("Valider")
dataStore.user.clubs.append(club.id)
}
self.dataStore.saveUser()
} }
.tint(isFavorite ? .green : .logoRed) .buttonStyle(.bordered)
} }
} }
} }

@ -13,10 +13,10 @@ struct ClubRowView: View {
var body: some View { var body: some View {
LabeledContent { LabeledContent {
if displayContext == .edition { // if displayContext == .edition {
Image(systemName: club.isFavorite() ? "star.fill" : "star") // Image(systemName: club.isFavorite() ? "star.fill" : "star")
.foregroundStyle(club.isFavorite() ? .green : .logoRed) // .foregroundStyle(club.isFavorite() ? .green : .logoRed)
} // }
} label: { } label: {
Text(club.name) Text(club.name)
Text(club.acronym) Text(club.acronym)

@ -20,7 +20,8 @@ struct EventCreationView: View {
@State private var eventName: String = "" @State private var eventName: String = ""
@State var tournaments: [Tournament] = [] @State var tournaments: [Tournament] = []
@State var selectedClub: Club? @State var selectedClub: Club?
@FocusState private var textFieldIsFocus: Bool
let multiTournamentsEventTip = MultiTournamentsEventTip() let multiTournamentsEventTip = MultiTournamentsEventTip()
var body: some View { var body: some View {
@ -63,9 +64,16 @@ struct EventCreationView: View {
} }
} }
TextField("Nom de l'événement", text: $eventName) VStack(alignment: .leading) {
.autocorrectionDisabled() Text("Nom de l'événement").font(.footnote)
.keyboardType(.alphabet) ZStack {
Text(eventName).hidden()
TextEditor(text: $eventName)
.focused($textFieldIsFocus)
.autocorrectionDisabled()
.keyboardType(.alphabet)
}
}
LabeledContent { LabeledContent {
Text(tournaments.count.formatted()) Text(tournaments.count.formatted())
@ -135,6 +143,19 @@ struct EventCreationView: View {
} }
.popoverTip(multiTournamentsEventTip) .popoverTip(multiTournamentsEventTip)
} }
ToolbarItemGroup(placement: .keyboard) {
if textFieldIsFocus {
Spacer()
Button {
textFieldIsFocus = false
} label: {
Text("Valider")
}
.buttonStyle(.bordered)
}
}
} }
.navigationTitle("Nouvel événement") .navigationTitle("Nouvel événement")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)

@ -10,9 +10,13 @@ import SwiftUI
struct OngoingView: View { struct OngoingView: View {
@Environment(NavigationViewModel.self) private var navigation: NavigationViewModel @Environment(NavigationViewModel.self) private var navigation: NavigationViewModel
@EnvironmentObject var dataStore: DataStore @EnvironmentObject var dataStore: DataStore
@State private var sortByField: Bool = false
let fieldSorting : [MySortDescriptor<Match>] = [.keyPath(\Match.courtIndex!), .keyPath(\Match.startDate!)]
let defaultSorting : [MySortDescriptor<Match>] = [.keyPath(\Match.startDate!), .keyPath(\Match.courtIndex!)]
var matches: [Match] { 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 { var body: some View {
@ -54,10 +58,10 @@ struct OngoingView: View {
.toolbar { .toolbar {
ToolbarItem(placement: .topBarLeading) { ToolbarItem(placement: .topBarLeading) {
Menu { Menu {
Button("Par terrain") { Picker(selection: $sortByField) {
Text("Trier par date").tag(false)
} Text("Trier par terrain").tag(true)
Button("Par date") { } label: {
} }
//todo //todo
@ -72,7 +76,7 @@ struct OngoingView: View {
} }
ToolbarItem(placement: .status) { ToolbarItem(placement: .status) {
if matches.isEmpty == false { if matches.isEmpty == false {
Text("\(matches.count) matche" + matches.count.pluralSuffix) Text("\(matches.count) match" + matches.count.pluralSuffix)
} }
} }
} }

@ -63,8 +63,12 @@ struct TournamentGeneralSettingsView: View {
.toolbar { .toolbar {
if textFieldIsFocus { if textFieldIsFocus {
ToolbarItem(placement: .keyboard) { ToolbarItem(placement: .keyboard) {
Button("Valider") { HStack {
textFieldIsFocus = false Spacer()
Button("Valider") {
textFieldIsFocus = false
}
.buttonStyle(.bordered)
} }
} }
} }

Loading…
Cancel
Save