diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 5d34828..d5ed00b 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3145,7 +3145,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.2.45; + MARKETING_VERSION = 1.2.46; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3191,7 +3191,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.2.45; + MARKETING_VERSION = 1.2.46; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/PadelClub/Data/Coredata/ImportedPlayer+Extensions.swift b/PadelClub/Data/Coredata/ImportedPlayer+Extensions.swift index d65f340..f5c929d 100644 --- a/PadelClub/Data/Coredata/ImportedPlayer+Extensions.swift +++ b/PadelClub/Data/Coredata/ImportedPlayer+Extensions.swift @@ -132,6 +132,6 @@ extension ImportedPlayer: PlayerHolder { fileprivate extension Int { var femaleInMaleAssimilation: Int { - self + TournamentCategory.femaleInMaleAssimilationAddition(self) + self + TournamentCategory.femaleInMaleAssimilationAddition(self, seasonYear: Date.now.seasonYear()) } } diff --git a/PadelClub/Extensions/Tournament+Extensions.swift b/PadelClub/Extensions/Tournament+Extensions.swift index a928ded..068a90b 100644 --- a/PadelClub/Extensions/Tournament+Extensions.swift +++ b/PadelClub/Extensions/Tournament+Extensions.swift @@ -172,7 +172,7 @@ extension Tournament { func isPlayerRankInadequate(player: PlayerHolder) -> Bool { guard let rank = player.getRank() else { return false } - let _rank = player.male ? rank : rank + PlayerRegistration.addon(for: rank, manMax: maleUnrankedValue ?? 0, womanMax: femaleUnrankedValue ?? 0) + let _rank = player.male ? rank : rank + addon(for: rank, manMax: maleUnrankedValue ?? 0, womanMax: femaleUnrankedValue ?? 0) if _rank <= tournamentLevel.minimumPlayerRank(category: tournamentCategory, ageCategory: federalTournamentAge) { return true } else { diff --git a/PadelClub/Views/Match/EditSharingView.swift b/PadelClub/Views/Match/EditSharingView.swift index 12a57e2..b8929f8 100644 --- a/PadelClub/Views/Match/EditSharingView.swift +++ b/PadelClub/Views/Match/EditSharingView.swift @@ -58,9 +58,9 @@ struct EditSharingView: View { messageData.append(message) guard - let labelOne = match.team(.one)?.teamLabelRanked( + let labelOne = match.team(.one)?.teamLabelRanked(displayStyle: .title, displayRank: displayRank, displayTeamName: displayTeamName), - let labelTwo = match.team(.two)?.teamLabelRanked( + let labelTwo = match.team(.two)?.teamLabelRanked(displayStyle: .title, displayRank: displayRank, displayTeamName: displayTeamName) else { return messageData.joined(separator: "\n") diff --git a/PadelClub/Views/Navigation/Agenda/ActivityView.swift b/PadelClub/Views/Navigation/Agenda/ActivityView.swift index 81c9bbf..9808f13 100644 --- a/PadelClub/Views/Navigation/Agenda/ActivityView.swift +++ b/PadelClub/Views/Navigation/Agenda/ActivityView.swift @@ -314,6 +314,7 @@ struct ActivityView: View { NavigationStack { TournamentLookUpView() .environment(federalDataViewModel) + .environment(navigation) } } .sheet(item: $newTournament) { tournament in diff --git a/PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift b/PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift index 3c5130b..d6417e7 100644 --- a/PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift +++ b/PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift @@ -9,10 +9,12 @@ import SwiftUI import CoreLocation import CoreLocationUI import PadelClubData +import LeStorage struct TournamentLookUpView: View { @EnvironmentObject var dataStore: DataStore @Environment(FederalDataViewModel.self) var federalDataViewModel: FederalDataViewModel + @Environment(NavigationViewModel.self) var navigationViewModel: NavigationViewModel @StateObject var locationManager = LocationManager() @Environment(\.dismiss) private var dismiss @FocusState private var isFocused: Bool @@ -27,11 +29,20 @@ struct TournamentLookUpView: View { @State private var presentAlert: Bool = false @State private var confirmSearch: Bool = false @State private var locationRequested = false - + @State private var apiError: StoreError? + var tournaments: [FederalTournament] { federalDataViewModel.searchedFederalTournaments } + var presentApiError: Binding { + Binding { + apiError != nil + } set: { value in + + } + } + var showLastError: Binding { Binding { locationManager.lastError != nil @@ -70,6 +81,26 @@ struct TournamentLookUpView: View { secondaryButton: .cancel() ) } + .alert(isPresented: presentApiError, error: apiError, actions: { storeError in + switch storeError { + case .missingUsername: + Button("Créer un compte ou se connecter") { + dismiss() + navigationViewModel.selectedTab = .umpire + } + default: + Button("D'accord") { + apiError = nil + } + } + }, message: { storeError in + switch storeError { + case .missingUsername: + Text("Un compte est requis pour utiliser ce service de Padel Club, veuillez créer un compte ou vous connecter.") + default: + Text("Une erreur est survenue, veuillez réessayer plus tard.") + } + }) .alert("Attention", isPresented: $presentAlert, actions: { Button { presentAlert = false @@ -79,7 +110,10 @@ struct TournamentLookUpView: View { Task { await getNewPage() searching = false - dismiss() + + if apiError == nil { + dismiss() + } } } label: { Label("Tout voir", systemImage: "arrow.down.circle") @@ -232,7 +266,7 @@ struct TournamentLookUpView: View { searching = false if tournaments.isEmpty == false && tournaments.count < total && total >= 200 && requestedToGetAllPages == false { presentAlert = true - } else { + } else if apiError == nil { dismiss() } } @@ -294,7 +328,9 @@ struct TournamentLookUpView: View { } else { print("finished") } - + } catch let error as StoreError { + print("getNewPage", error) + apiError = error } catch { print("getNewPage", error) } diff --git a/PadelClub/Views/Player/PlayerDetailView.swift b/PadelClub/Views/Player/PlayerDetailView.swift index 1633df7..3b1eaa8 100644 --- a/PadelClub/Views/Player/PlayerDetailView.swift +++ b/PadelClub/Views/Player/PlayerDetailView.swift @@ -157,7 +157,7 @@ struct PlayerDetailView: View { } } else if player.isMalePlayer() == false && tournament.tournamentCategory == .men, let rank = player.rank { Section { - let value = PlayerRegistration.addon(for: rank, manMax: maxMaleUnrankedValue, womanMax: tournament.femaleUnrankedValue ?? 0) + let value = tournament.addon(for: rank, manMax: maxMaleUnrankedValue, womanMax: tournament.femaleUnrankedValue ?? 0) LabeledContent { Text(value.formatted()) } label: { diff --git a/PadelClub/Views/Team/EditingTeamView.swift b/PadelClub/Views/Team/EditingTeamView.swift index d239148..6136e36 100644 --- a/PadelClub/Views/Team/EditingTeamView.swift +++ b/PadelClub/Views/Team/EditingTeamView.swift @@ -268,7 +268,7 @@ struct EditingTeamView: View { Text("Nom de l'équipe") } - if tournament.tournamentLevel.coachingIsAuthorized { + if tournament.coachingIsAuthorized() { CoachListView(team: team) } diff --git a/PadelClub/Views/Tournament/FileImportView.swift b/PadelClub/Views/Tournament/FileImportView.swift index 70b82c2..0295501 100644 --- a/PadelClub/Views/Tournament/FileImportView.swift +++ b/PadelClub/Views/Tournament/FileImportView.swift @@ -64,6 +64,7 @@ enum FileImportCustomField: Int, Identifiable, CaseIterable { struct FileImportView: View { @EnvironmentObject var dataStore: DataStore + @Environment(NavigationViewModel.self) var navigationViewModel: NavigationViewModel @Environment(Tournament.self) var tournament: Tournament @Environment(\.dismiss) private var dismiss @@ -84,7 +85,16 @@ struct FileImportView: View { @State private var presentFormatHelperView: Bool = false @State private var validatedTournamentIds: Set = Set() @State private var chunkMode: ChunkMode = .byParameter - + @State private var apiError: StoreError? + + var presentApiError: Binding { + Binding { + apiError != nil + } set: { value in + + } + } + enum ChunkMode: Int, Identifiable, CaseIterable { var id: Int { self.rawValue } case byParameter @@ -175,7 +185,11 @@ struct FileImportView: View { if let fileContent { do { try await _startImport(fileContent: fileContent, allTournaments: false) + } catch let error as StoreError { + Logger.error(error) + apiError = error } catch { + Logger.error(error) errorMessage = error.localizedDescription } } @@ -199,7 +213,11 @@ struct FileImportView: View { if let fileContent { do { try await _startImport(fileContent: fileContent, allTournaments: true) + } catch let error as StoreError { + Logger.error(error) + apiError = error } catch { + Logger.error(error) errorMessage = error.localizedDescription } } @@ -306,7 +324,11 @@ struct FileImportView: View { if let fileContent { do { try await _startImport(fileContent: fileContent, allTournaments: false) + } catch let error as StoreError { + Logger.error(error) + apiError = error } catch { + Logger.error(error) errorMessage = error.localizedDescription } } @@ -381,6 +403,26 @@ struct FileImportView: View { } .navigationBarTitleDisplayMode(.inline) .toolbarBackground(.visible, for: .navigationBar) + .alert(isPresented: presentApiError, error: apiError, actions: { storeError in + switch storeError { + case .missingUsername: + Button("Créer un compte ou se connecter") { + dismiss() + navigationViewModel.selectedTab = .umpire + } + default: + Button("D'accord") { + apiError = nil + } + } + }, message: { storeError in + switch storeError { + case .missingUsername: + Text("Un compte est requis pour utiliser ce service de Padel Club, veuillez créer un compte ou vous connecter.") + default: + Text("Une erreur est survenue, veuillez réessayer plus tard.") + } + }) .sheet(isPresented: $presentFormatHelperView) { NavigationStack { List { @@ -434,6 +476,9 @@ struct FileImportView: View { fileContent = try String(contentsOf: selectedFile) } selectedFile.stopAccessingSecurityScopedResource() + } catch let error as StoreError { + Logger.error(error) + apiError = error } catch { Logger.error(error) errorMessage = error.localizedDescription @@ -453,6 +498,7 @@ struct FileImportView: View { do { fileContent = try String(contentsOf: url) } catch { + Logger.error(error) errorMessage = error.localizedDescription } } diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index cde3a24..89b091d 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -285,6 +285,7 @@ struct InscriptionManagerView: View { }) { NavigationStack { FileImportView(defaultFileProvider: tournament.isAnimation() ? .custom : .frenchFederation) + .environment(navigation) } .tint(.master) }