diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 9a82ca4..0da430b 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -1830,7 +1830,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 7; + CURRENT_PROJECT_VERSION = 8; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -1868,7 +1868,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 7; + CURRENT_PROJECT_VERSION = 8; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/Federal/FederalTournament.swift b/PadelClub/Data/Federal/FederalTournament.swift index 5437c25..4d142cb 100644 --- a/PadelClub/Data/Federal/FederalTournament.swift +++ b/PadelClub/Data/Federal/FederalTournament.swift @@ -17,16 +17,7 @@ enum DayPeriod { struct FederalTournament: Identifiable, Codable { func getEvent() -> Event { - var club = DataStore.shared.clubs.first(where: { $0.code == codeClub }) - if club == nil { - club = Club.findOrCreate(name: clubLabel(), code: codeClub) - do { - try DataStore.shared.clubs.addOrUpdate(instance: club!) - } catch { - Logger.error(error) - } - } - + let club = DataStore.shared.user.clubsObjects().first(where: { $0.code == codeClub }) var event = DataStore.shared.events.first(where: { $0.tenupId == id.string }) if event == nil { event = Event(creator: DataStore.shared.user.id, club: club?.id, name: libelle, tenupId: id.string) diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index f39e06c..7baf738 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -306,7 +306,7 @@ class Tournament : ModelObject, Storable { } func publishedGroupStagesDate() -> Date? { - if let first = groupStages().flatMap({ $0.playedMatches() }).compactMap({ $0.startDate }).sorted().first?.atNine() { + if let first = groupStages().flatMap({ $0.playedMatches() }).compactMap({ $0.startDate }).sorted().first?.atEightAM() { if first.isEarlierThan(startDate) { return startDate } else { @@ -327,7 +327,7 @@ class Tournament : ModelObject, Storable { } func publishedBracketsDate() -> Date? { - if let first = rounds().flatMap({ $0.playedMatches() }).compactMap({ $0.startDate }).sorted().first?.atNine() { + if let first = rounds().flatMap({ $0.playedMatches() }).compactMap({ $0.startDate }).sorted().first?.atEightAM() { if first.isEarlierThan(startDate) { return startDate } else { @@ -1361,9 +1361,9 @@ class Tournament : ModelObject, Storable { private func _defaultSorting() -> [MySortDescriptor] { switch teamSorting { case .rank: - [.keyPath(\TeamRegistration.initialWeight), .keyPath(\TeamRegistration.registrationDate!), .keyPath(\.canonicalName)] + [.keyPath(\TeamRegistration.initialWeight), .keyPath(\TeamRegistration.registrationDate!)] case .inscriptionDate: - [.keyPath(\TeamRegistration.registrationDate!), .keyPath(\TeamRegistration.initialWeight), .keyPath(\.canonicalName)] + [.keyPath(\TeamRegistration.registrationDate!), .keyPath(\TeamRegistration.initialWeight)] } } @@ -1373,7 +1373,7 @@ class Tournament : ModelObject, Storable { && federalTournamentAge == build.age } - private let _currentSelectionSorting : [MySortDescriptor] = [.keyPath(\.weight), .keyPath(\.registrationDate!), .keyPath(\.canonicalName)] + private let _currentSelectionSorting : [MySortDescriptor] = [.keyPath(\.weight), .keyPath(\.registrationDate!)] override func deleteDependencies() throws { try Store.main.deleteDependencies(items: self.unsortedTeams()) diff --git a/PadelClub/Extensions/Date+Extensions.swift b/PadelClub/Extensions/Date+Extensions.swift index 15c7272..0c20d51 100644 --- a/PadelClub/Extensions/Date+Extensions.swift +++ b/PadelClub/Extensions/Date+Extensions.swift @@ -81,7 +81,7 @@ extension Date { func get(_ components: Calendar.Component..., calendar: Calendar = Calendar.current) -> DateComponents { return calendar.dateComponents(Set(components), from: self) } - + func get(_ component: Calendar.Component, calendar: Calendar = Calendar.current) -> Int { return calendar.component(component, from: self) } @@ -102,100 +102,100 @@ extension Date { } static var firstDayOfWeek = Calendar.current.firstWeekday - static var capitalizedFirstLettersOfWeekdays: [String] { - let calendar = Calendar.current - // let weekdays = calendar.shortWeekdaySymbols - - // return weekdays.map { weekday in - // guard let firstLetter = weekday.first else { return "" } - // return String(firstLetter).capitalized - // } - // Adjusted for the different weekday starts - var weekdays = calendar.veryShortStandaloneWeekdaySymbols - if firstDayOfWeek > 1 { - for _ in 1..= firstWeekDayBeforeStart && $0 <= endOfMonth }.sorted(by: <) - } - - var monthInt: Int { - Calendar.current.component(.month, from: self) - } - - var yearInt: Int { - Calendar.current.component(.year, from: self) - } - - var dayInt: Int { - Calendar.current.component(.day, from: self) - } - - var startOfDay: Date { - Calendar.current.startOfDay(for: self) - } + static var capitalizedFirstLettersOfWeekdays: [String] { + let calendar = Calendar.current + // let weekdays = calendar.shortWeekdaySymbols + + // return weekdays.map { weekday in + // guard let firstLetter = weekday.first else { return "" } + // return String(firstLetter).capitalized + // } + // Adjusted for the different weekday starts + var weekdays = calendar.veryShortStandaloneWeekdaySymbols + if firstDayOfWeek > 1 { + for _ in 1..= firstWeekDayBeforeStart && $0 <= endOfMonth }.sorted(by: <) + } + + var monthInt: Int { + Calendar.current.component(.month, from: self) + } + + var yearInt: Int { + Calendar.current.component(.year, from: self) + } + + var dayInt: Int { + Calendar.current.component(.day, from: self) + } + + var startOfDay: Date { + Calendar.current.startOfDay(for: self) + } func endOfDay() -> Date { let calendar = Calendar.current @@ -206,6 +206,11 @@ extension Date { let calendar = Calendar.current return calendar.date(bySettingHour: 9, minute: 0, second: 0, of: self)! } + + func atEightAM() -> Date { + let calendar = Calendar.current + return calendar.date(bySettingHour: 8, minute: 0, second: 0, of: self)! + } } extension Date { diff --git a/PadelClub/Views/Club/ClubSearchView.swift b/PadelClub/Views/Club/ClubSearchView.swift index bb7aef9..4d6c14e 100644 --- a/PadelClub/Views/Club/ClubSearchView.swift +++ b/PadelClub/Views/Club/ClubSearchView.swift @@ -83,30 +83,7 @@ struct ClubSearchView: View { ForEach(_filteredClubs()) { clubMark in Button { let clubToEdit = club ?? Club.findOrCreate(name: clubMark.nom, code: clubMark.clubID) - - if clubToEdit.creator == dataStore.user.id { - if clubToEdit.name.isEmpty { - clubToEdit.name = clubMark.nom - clubToEdit.acronym = clubToEdit.automaticShortName() - } - clubToEdit.code = clubMark.clubID - clubToEdit.latitude = clubMark.lat - clubToEdit.longitude = clubMark.lng - clubToEdit.city = clubMark.ville - } - - if displayContext == .addition { - do { - try dataStore.clubs.addOrUpdate(instance: clubToEdit) - if dataStore.user.clubs.contains(where: { $0 == clubToEdit.id }) == false { - dataStore.user.clubs.append(clubToEdit.id) - self.dataStore.saveUser() - } - } catch { - Logger.error(error) - } - } - dismiss() + _importClub(clubToEdit: clubToEdit, clubMarker: clubMark) } label: { clubView(clubMark) .frame(maxWidth: .infinity) @@ -133,6 +110,13 @@ struct ClubSearchView: View { } } } + .task { + do { + try await dataStore.clubs.loadDataFromServerIfAllowed() + } catch { + Logger.error(error) + } + } .listStyle(.grouped) .onChange(of: searchPresented) { locationManager.lastError = nil @@ -307,6 +291,32 @@ struct ClubSearchView: View { // } } } + + private func _importClub(clubToEdit: Club, clubMarker: ClubMarker) { + if clubToEdit.creator == dataStore.user.id { + if clubToEdit.name.isEmpty { + clubToEdit.name = clubMarker.nom + clubToEdit.acronym = clubToEdit.automaticShortName() + } + clubToEdit.code = clubMarker.clubID + clubToEdit.latitude = clubMarker.lat + clubToEdit.longitude = clubMarker.lng + clubToEdit.city = clubMarker.ville + } + + if displayContext == .addition { + do { + try dataStore.clubs.addOrUpdate(instance: clubToEdit) + if dataStore.user.clubs.contains(where: { $0 == clubToEdit.id }) == false { + dataStore.user.clubs.append(clubToEdit.id) + self.dataStore.saveUser() + } + } catch { + Logger.error(error) + } + } + dismiss() + } private func _filteredClubs() -> [ClubMarker] { clubMarkers.filter({ _isClubValidForSearchedTerms(club: $0) }) diff --git a/PadelClub/Views/Club/CreateClubView.swift b/PadelClub/Views/Club/CreateClubView.swift index 91e2794..5f8f326 100644 --- a/PadelClub/Views/Club/CreateClubView.swift +++ b/PadelClub/Views/Club/CreateClubView.swift @@ -21,6 +21,13 @@ struct CreateClubView: View { var body: some View { NavigationStack { ClubDetailView(club: club, displayContext: .addition) + .task { + do { + try await dataStore.clubs.loadDataFromServerIfAllowed() + } catch { + Logger.error(error) + } + } .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Annuler", role: .cancel) { diff --git a/PadelClub/Views/Navigation/Umpire/UmpireView.swift b/PadelClub/Views/Navigation/Umpire/UmpireView.swift index 519b263..bcff6bd 100644 --- a/PadelClub/Views/Navigation/Umpire/UmpireView.swift +++ b/PadelClub/Views/Navigation/Umpire/UmpireView.swift @@ -189,6 +189,13 @@ struct UmpireView: View { } }) } + .task { + do { + try await dataStore.clubs.loadDataFromServerIfAllowed() + } catch { + Logger.error(error) + } + } } } } diff --git a/PadelClub/Views/Tournament/Screen/BroadcastView.swift b/PadelClub/Views/Tournament/Screen/BroadcastView.swift index 4a7499f..027401c 100644 --- a/PadelClub/Views/Tournament/Screen/BroadcastView.swift +++ b/PadelClub/Views/Tournament/Screen/BroadcastView.swift @@ -52,8 +52,8 @@ struct BroadcastView: View { } else { Text("Publication prévue") } - Text("Les horaires de convocations ne seront pas publiés") } + Text("Les horaires de convocations ne seront pas publiés").foregroundStyle(.secondary) } header: { Text("Liste des équipes") } footer: { diff --git a/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift b/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift index bc17610..6d9591d 100644 --- a/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift +++ b/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift @@ -17,10 +17,12 @@ struct TournamentStatusView: View { var body: some View { @Bindable var tournament = tournament Form { + #if DEBUG RowButtonView("debug: Un-delete le tournoi") { tournament.endDate = nil tournament.isDeleted.toggle() } + #endif Section { if tournament.endDate == nil { @@ -71,7 +73,7 @@ struct TournamentStatusView: View { Text("Tournoi privé") } } footer: { - Text("Le tournoi sera masqué sur le site padelclub.app") + Text(.init("Le tournoi sera masqué sur le site [Padel Club](\(URLs.main)")) } } .toolbarBackground(.visible, for: .navigationBar) diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index 8458166..63a85d8 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -149,7 +149,7 @@ struct InscriptionManagerView: View { rankingDateSourcePickerView(showDateInLabel: true) if tournament.teamSorting == .inscriptionDate { Divider() - _prioritizeClubMembersButton() + //_prioritizeClubMembersButton() Button("Bloquer une place") { _createTeam() diff --git a/PadelClub/Views/Tournament/TournamentView.swift b/PadelClub/Views/Tournament/TournamentView.swift index cbc9b51..58c7792 100644 --- a/PadelClub/Views/Tournament/TournamentView.swift +++ b/PadelClub/Views/Tournament/TournamentView.swift @@ -10,6 +10,7 @@ import LeStorage struct TournamentView: View { @EnvironmentObject var dataStore: DataStore + @Environment(NavigationViewModel.self) var navigation: NavigationViewModel @Environment(Tournament.self) var tournament: Tournament var presentationContext: PresentationContext = .agenda @@ -126,7 +127,7 @@ struct TournamentView: View { Menu { if presentationContext == .agenda { Button { - + navigation.openTournamentInOrganizer(tournament) } label: { Label("Voir dans le gestionnaire", systemImage: "line.diagonal.arrow") }