fix club stuff

multistore
Razmig Sarkissian 2 years ago
parent d6f8a711a7
commit c70661b394
  1. 11
      PadelClub/Data/Federal/FederalTournament.swift
  2. 4
      PadelClub/Data/Tournament.swift
  3. 5
      PadelClub/Extensions/Date+Extensions.swift
  4. 17
      PadelClub/Views/Club/ClubSearchView.swift
  5. 7
      PadelClub/Views/Club/CreateClubView.swift
  6. 7
      PadelClub/Views/Navigation/Umpire/UmpireView.swift
  7. 2
      PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift
  8. 3
      PadelClub/Views/Tournament/TournamentView.swift

@ -17,16 +17,7 @@ enum DayPeriod {
struct FederalTournament: Identifiable, Codable { struct FederalTournament: Identifiable, Codable {
func getEvent() -> Event { func getEvent() -> Event {
var club = DataStore.shared.clubs.first(where: { $0.code == codeClub }) let club = DataStore.shared.user.clubsObjects().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)
}
}
var event = DataStore.shared.events.first(where: { $0.tenupId == id.string }) var event = DataStore.shared.events.first(where: { $0.tenupId == id.string })
if event == nil { if event == nil {
event = Event(creator: DataStore.shared.user.id, club: club?.id, name: libelle, tenupId: id.string) event = Event(creator: DataStore.shared.user.id, club: club?.id, name: libelle, tenupId: id.string)

@ -306,7 +306,7 @@ class Tournament : ModelObject, Storable {
} }
func publishedGroupStagesDate() -> Date? { 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) { if first.isEarlierThan(startDate) {
return startDate return startDate
} else { } else {
@ -327,7 +327,7 @@ class Tournament : ModelObject, Storable {
} }
func publishedBracketsDate() -> Date? { 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) { if first.isEarlierThan(startDate) {
return startDate return startDate
} else { } else {

@ -206,6 +206,11 @@ extension Date {
let calendar = Calendar.current let calendar = Calendar.current
return calendar.date(bySettingHour: 9, minute: 0, second: 0, of: self)! 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 { extension Date {

@ -110,6 +110,13 @@ struct ClubSearchView: View {
} }
} }
} }
.task {
do {
try dataStore.clubs.loadDataFromServerIfAllowed()
} catch {
Logger.error(error)
}
}
.listStyle(.grouped) .listStyle(.grouped)
.onChange(of: searchPresented) { .onChange(of: searchPresented) {
locationManager.lastError = nil locationManager.lastError = nil
@ -288,13 +295,13 @@ struct ClubSearchView: View {
private func _importClub(clubToEdit: Club, clubMarker: ClubMarker) { private func _importClub(clubToEdit: Club, clubMarker: ClubMarker) {
if clubToEdit.creator == dataStore.user.id { if clubToEdit.creator == dataStore.user.id {
if clubToEdit.name.isEmpty { if clubToEdit.name.isEmpty {
clubToEdit.name = clubMark.nom clubToEdit.name = clubMarker.nom
clubToEdit.acronym = clubToEdit.automaticShortName() clubToEdit.acronym = clubToEdit.automaticShortName()
} }
clubToEdit.code = clubMark.clubID clubToEdit.code = clubMarker.clubID
clubToEdit.latitude = clubMark.lat clubToEdit.latitude = clubMarker.lat
clubToEdit.longitude = clubMark.lng clubToEdit.longitude = clubMarker.lng
clubToEdit.city = clubMark.ville clubToEdit.city = clubMarker.ville
} }
if displayContext == .addition { if displayContext == .addition {

@ -21,6 +21,13 @@ struct CreateClubView: View {
var body: some View { var body: some View {
NavigationStack { NavigationStack {
ClubDetailView(club: club, displayContext: .addition) ClubDetailView(club: club, displayContext: .addition)
.task {
do {
try dataStore.clubs.loadDataFromServerIfAllowed()
} catch {
Logger.error(error)
}
}
.toolbar { .toolbar {
ToolbarItem(placement: .cancellationAction) { ToolbarItem(placement: .cancellationAction) {
Button("Annuler", role: .cancel) { Button("Annuler", role: .cancel) {

@ -172,6 +172,13 @@ struct UmpireView: View {
} }
}) })
} }
.task {
do {
try dataStore.clubs.loadDataFromServerIfAllowed()
} catch {
Logger.error(error)
}
}
} }
} }
} }

@ -17,10 +17,12 @@ struct TournamentStatusView: View {
var body: some View { var body: some View {
@Bindable var tournament = tournament @Bindable var tournament = tournament
Form { Form {
#if DEBUG
RowButtonView("debug: Un-delete le tournoi") { RowButtonView("debug: Un-delete le tournoi") {
tournament.endDate = nil tournament.endDate = nil
tournament.isDeleted.toggle() tournament.isDeleted.toggle()
} }
#endif
Section { Section {
if tournament.endDate == nil { if tournament.endDate == nil {

@ -10,6 +10,7 @@ import LeStorage
struct TournamentView: View { struct TournamentView: View {
@EnvironmentObject var dataStore: DataStore @EnvironmentObject var dataStore: DataStore
@Environment(NavigationViewModel.self) var navigation: NavigationViewModel
@Environment(Tournament.self) var tournament: Tournament @Environment(Tournament.self) var tournament: Tournament
var presentationContext: PresentationContext = .agenda var presentationContext: PresentationContext = .agenda
@ -126,7 +127,7 @@ struct TournamentView: View {
Menu { Menu {
if presentationContext == .agenda { if presentationContext == .agenda {
Button { Button {
navigation.openTournamentInOrganizer(tournament)
} label: { } label: {
Label("Voir dans le gestionnaire", systemImage: "line.diagonal.arrow") Label("Voir dans le gestionnaire", systemImage: "line.diagonal.arrow")
} }

Loading…
Cancel
Save