From d6f8a711a7fcf418e9e1ccefaf2a26c9a86f8c6b Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 16 May 2024 11:14:15 +0200 Subject: [PATCH 1/4] clean up --- PadelClub/Views/Club/ClubSearchView.swift | 51 ++++++++++++----------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/PadelClub/Views/Club/ClubSearchView.swift b/PadelClub/Views/Club/ClubSearchView.swift index bb7aef9..6d628a6 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) @@ -307,6 +284,32 @@ struct ClubSearchView: View { // } } } + + private func _importClub(clubToEdit: Club, clubMarker: ClubMarker) { + 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() + } private func _filteredClubs() -> [ClubMarker] { clubMarkers.filter({ _isClubValidForSearchedTerms(club: $0) }) From c70661b3943254f4b35fc960da91a67a01476465 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 16 May 2024 17:26:53 +0200 Subject: [PATCH 2/4] fix club stuff --- .../Data/Federal/FederalTournament.swift | 11 +- PadelClub/Data/Tournament.swift | 4 +- PadelClub/Extensions/Date+Extensions.swift | 195 +++++++++--------- PadelClub/Views/Club/ClubSearchView.swift | 17 +- PadelClub/Views/Club/CreateClubView.swift | 7 + .../Views/Navigation/Umpire/UmpireView.swift | 7 + .../Components/TournamentStatusView.swift | 2 + .../Views/Tournament/TournamentView.swift | 3 +- 8 files changed, 133 insertions(+), 113 deletions(-) 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..cff8a4e 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 { 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 6d628a6..3956e96 100644 --- a/PadelClub/Views/Club/ClubSearchView.swift +++ b/PadelClub/Views/Club/ClubSearchView.swift @@ -110,6 +110,13 @@ struct ClubSearchView: View { } } } + .task { + do { + try dataStore.clubs.loadDataFromServerIfAllowed() + } catch { + Logger.error(error) + } + } .listStyle(.grouped) .onChange(of: searchPresented) { locationManager.lastError = nil @@ -288,13 +295,13 @@ struct ClubSearchView: View { private func _importClub(clubToEdit: Club, clubMarker: ClubMarker) { if clubToEdit.creator == dataStore.user.id { if clubToEdit.name.isEmpty { - clubToEdit.name = clubMark.nom + clubToEdit.name = clubMarker.nom clubToEdit.acronym = clubToEdit.automaticShortName() } - clubToEdit.code = clubMark.clubID - clubToEdit.latitude = clubMark.lat - clubToEdit.longitude = clubMark.lng - clubToEdit.city = clubMark.ville + clubToEdit.code = clubMarker.clubID + clubToEdit.latitude = clubMarker.lat + clubToEdit.longitude = clubMarker.lng + clubToEdit.city = clubMarker.ville } if displayContext == .addition { diff --git a/PadelClub/Views/Club/CreateClubView.swift b/PadelClub/Views/Club/CreateClubView.swift index 91e2794..608a4ac 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 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 ec62254..adb6738 100644 --- a/PadelClub/Views/Navigation/Umpire/UmpireView.swift +++ b/PadelClub/Views/Navigation/Umpire/UmpireView.swift @@ -172,6 +172,13 @@ struct UmpireView: View { } }) } + .task { + do { + try dataStore.clubs.loadDataFromServerIfAllowed() + } catch { + Logger.error(error) + } + } } } } diff --git a/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift b/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift index bc17610..549a2a0 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 { 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") } From 5ea13576550f16a799706839a5b91ef320fdfad3 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 16 May 2024 22:44:07 +0200 Subject: [PATCH 3/4] build 8 --- PadelClub.xcodeproj/project.pbxproj | 4 ++-- PadelClub/Data/Tournament.swift | 6 +++--- PadelClub/Views/Tournament/Screen/BroadcastView.swift | 2 +- .../Tournament/Screen/Components/TournamentStatusView.swift | 2 +- .../Views/Tournament/Screen/InscriptionManagerView.swift | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) 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/Tournament.swift b/PadelClub/Data/Tournament.swift index cff8a4e..7baf738 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -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/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 549a2a0..6d9591d 100644 --- a/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift +++ b/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift @@ -73,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() From 309c7fc199b7dc124c2999b4c88e0f0a2e9e0cdd Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 16 May 2024 22:49:37 +0200 Subject: [PATCH 4/4] fix await stuff --- PadelClub/Views/Club/ClubSearchView.swift | 2 +- PadelClub/Views/Club/CreateClubView.swift | 2 +- PadelClub/Views/Navigation/Umpire/UmpireView.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PadelClub/Views/Club/ClubSearchView.swift b/PadelClub/Views/Club/ClubSearchView.swift index 3956e96..4d6c14e 100644 --- a/PadelClub/Views/Club/ClubSearchView.swift +++ b/PadelClub/Views/Club/ClubSearchView.swift @@ -112,7 +112,7 @@ struct ClubSearchView: View { } .task { do { - try dataStore.clubs.loadDataFromServerIfAllowed() + try await dataStore.clubs.loadDataFromServerIfAllowed() } catch { Logger.error(error) } diff --git a/PadelClub/Views/Club/CreateClubView.swift b/PadelClub/Views/Club/CreateClubView.swift index 608a4ac..5f8f326 100644 --- a/PadelClub/Views/Club/CreateClubView.swift +++ b/PadelClub/Views/Club/CreateClubView.swift @@ -23,7 +23,7 @@ struct CreateClubView: View { ClubDetailView(club: club, displayContext: .addition) .task { do { - try dataStore.clubs.loadDataFromServerIfAllowed() + try await dataStore.clubs.loadDataFromServerIfAllowed() } catch { Logger.error(error) } diff --git a/PadelClub/Views/Navigation/Umpire/UmpireView.swift b/PadelClub/Views/Navigation/Umpire/UmpireView.swift index adb6738..b8d983f 100644 --- a/PadelClub/Views/Navigation/Umpire/UmpireView.swift +++ b/PadelClub/Views/Navigation/Umpire/UmpireView.swift @@ -174,7 +174,7 @@ struct UmpireView: View { } .task { do { - try dataStore.clubs.loadDataFromServerIfAllowed() + try await dataStore.clubs.loadDataFromServerIfAllowed() } catch { Logger.error(error) }