fix club stuff

multistore
Razmig Sarkissian 1 year ago
parent eb7acc1299
commit 15bb8f879a
  1. 22
      PadelClub/Views/Cashier/Event/EventSettingsView.swift
  2. 47
      PadelClub/Views/Club/ClubDetailView.swift
  3. 8
      PadelClub/Views/Club/ClubRowView.swift
  4. 23
      PadelClub/Views/Event/EventCreationView.swift
  5. 16
      PadelClub/Views/Navigation/Ongoing/OngoingView.swift
  6. 4
      PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.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,7 +22,10 @@ struct EventSettingsView: View {
var body: some View {
Form {
Section {
TextField("Nom de l'événement", text: $eventName)
ZStack {
Text(eventName).hidden()
TextEditor(text: $eventName)
.focused($textFieldIsFocus)
.autocorrectionDisabled()
.keyboardType(.alphabet)
.onSubmit {
@ -32,6 +36,9 @@ struct EventSettingsView: View {
}
_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() {

@ -31,7 +31,9 @@ struct ClubDetailView: View {
var body: some View {
Form {
Section {
TextField("Nom du club", text: $club.name)
ZStack {
Text(club.name).hidden()
TextEditor(text: $club.name)
.autocorrectionDisabled()
.keyboardType(.alphabet)
.frame(maxWidth: .infinity)
@ -46,8 +48,9 @@ struct ClubDetailView: View {
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)
}
}
}

@ -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)

@ -20,6 +20,7 @@ struct EventCreationView: View {
@State private var eventName: String = ""
@State var tournaments: [Tournament] = []
@State var selectedClub: Club?
@FocusState private var textFieldIsFocus: Bool
let multiTournamentsEventTip = MultiTournamentsEventTip()
@ -63,9 +64,16 @@ struct EventCreationView: View {
}
}
TextField("Nom de l'événement", text: $eventName)
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)

@ -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<Match>] = [.keyPath(\Match.courtIndex!), .keyPath(\Match.startDate!)]
let defaultSorting : [MySortDescriptor<Match>] = [.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)
}
}
}

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

Loading…
Cancel
Save