|
|
|
|
@ -334,6 +334,7 @@ struct ClubSearchView: View { |
|
|
|
|
clubToEdit.latitude = clubMarker.lat |
|
|
|
|
clubToEdit.longitude = clubMarker.lng |
|
|
|
|
clubToEdit.city = clubMarker.ville |
|
|
|
|
clubToEdit.courtCount = clubMarker.numberOfCourts(for: "Padel") ?? 2 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if displayContext == .addition && clubToEdit.hasBeenCreated(by: StoreCenter.main.userId) { |
|
|
|
|
@ -420,6 +421,40 @@ struct ClubMarker: Codable, Hashable, Identifiable { |
|
|
|
|
let pratiques: [Pratique] |
|
|
|
|
let lat, lng: Double |
|
|
|
|
|
|
|
|
|
// Method to get the number of courts for a specific sport |
|
|
|
|
func numberOfCourts(for sport: String) -> Int? { |
|
|
|
|
// Split the `terrainPratiqueLibelle` string into components |
|
|
|
|
let components = terrainPratiqueLibelle.split(separator: ",") |
|
|
|
|
|
|
|
|
|
// Iterate through the components to find the relevant sport or general number of courts |
|
|
|
|
for component in components { |
|
|
|
|
let trimmedComponent = component.trimmingCharacters(in: .whitespacesAndNewlines) |
|
|
|
|
|
|
|
|
|
// Check if the component explicitly mentions the sport |
|
|
|
|
if let colonIndex = trimmedComponent.firstIndex(of: ":") { |
|
|
|
|
let sportName = trimmedComponent[..<colonIndex].trimmingCharacters(in: .whitespacesAndNewlines) |
|
|
|
|
let courtsString = trimmedComponent[trimmedComponent.index(after: colonIndex)...].trimmingCharacters(in: .whitespacesAndNewlines) |
|
|
|
|
|
|
|
|
|
// If the sport matches the requested sport, return the number of courts |
|
|
|
|
if sportName.lowercased() == sport.lowercased() { |
|
|
|
|
if let courtsNumber = courtsString.split(separator: " ").first, |
|
|
|
|
let courts = Int(courtsNumber) { |
|
|
|
|
return courts |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if pratiques.count == 1 && pratiques.first?.rawValue.lowercased() == sport.lowercased() { |
|
|
|
|
// Handle cases where only the number of courts is provided (e.g., "2 terrains") |
|
|
|
|
if let courtsNumber = trimmedComponent.split(separator: " ").first, |
|
|
|
|
let courts = Int(courtsNumber) { |
|
|
|
|
return courts |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Return nil if the sport or number of courts is not found |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var location: CLLocation { |
|
|
|
|
CLLocation(latitude: lat, longitude: lng) |
|
|
|
|
} |
|
|
|
|
|