|
|
|
|
@ -28,6 +28,7 @@ struct ClubSearchView: View { |
|
|
|
|
@State private var showingSettingsAlert = false |
|
|
|
|
@State private var newClub: Club? |
|
|
|
|
@State private var error: Error? |
|
|
|
|
@State private var selectedClubId: String? |
|
|
|
|
|
|
|
|
|
var presentClubCreationView: Binding<Bool> { Binding( |
|
|
|
|
get: { newClub != nil }, |
|
|
|
|
@ -90,8 +91,18 @@ struct ClubSearchView: View { |
|
|
|
|
Section { |
|
|
|
|
ForEach(_filteredClubs()) { clubMark in |
|
|
|
|
Button { |
|
|
|
|
let clubToEdit = club ?? Club.findOrCreate(name: clubMark.nom, code: clubMark.clubID) |
|
|
|
|
_importClub(clubToEdit: clubToEdit, clubMarker: clubMark) |
|
|
|
|
Task { |
|
|
|
|
selectedClubId = clubMark.id |
|
|
|
|
do { |
|
|
|
|
dataStore.clubs.reset() |
|
|
|
|
try await dataStore.clubs.loadDataFromServerIfAllowed() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
let clubToEdit = club ?? Club.findOrCreate(name: clubMark.nom, code: clubMark.clubID) |
|
|
|
|
_importClub(clubToEdit: clubToEdit, clubMarker: clubMark) |
|
|
|
|
selectedClubId = nil |
|
|
|
|
} |
|
|
|
|
} label: { |
|
|
|
|
clubView(clubMark) |
|
|
|
|
.contentShape(Rectangle()) |
|
|
|
|
@ -118,13 +129,6 @@ struct ClubSearchView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.task { |
|
|
|
|
do { |
|
|
|
|
try await dataStore.clubs.loadDataFromServerIfAllowed() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.listStyle(.grouped) |
|
|
|
|
.onChange(of: searchPresented) { |
|
|
|
|
locationManager.lastError = nil |
|
|
|
|
@ -385,7 +389,11 @@ struct ClubSearchView: View { |
|
|
|
|
@ViewBuilder |
|
|
|
|
private func clubView(_ club: ClubMarker) -> some View { |
|
|
|
|
LabeledContent { |
|
|
|
|
Text(club.distance(from: locationManager.location)) |
|
|
|
|
if club.id == selectedClubId { |
|
|
|
|
ProgressView() |
|
|
|
|
} else { |
|
|
|
|
Text(club.distance(from: locationManager.location)) |
|
|
|
|
} |
|
|
|
|
} label: { |
|
|
|
|
Text(club.nom).lineLimit(1) |
|
|
|
|
Text(club.ville).font(.caption) |
|
|
|
|
|