|
|
|
|
@ -14,6 +14,7 @@ struct TournamentLookUpView: View { |
|
|
|
|
@Environment(FederalDataViewModel.self) var federalDataViewModel: FederalDataViewModel |
|
|
|
|
@StateObject var locationManager = LocationManager() |
|
|
|
|
@Environment(\.dismiss) private var dismiss |
|
|
|
|
@FocusState private var isFocused: Bool |
|
|
|
|
|
|
|
|
|
@State private var searchField: String = "" |
|
|
|
|
@State var page: Int = 0 |
|
|
|
|
@ -24,6 +25,7 @@ struct TournamentLookUpView: View { |
|
|
|
|
@State private var revealSearchParameters: Bool = true |
|
|
|
|
@State private var presentAlert: Bool = false |
|
|
|
|
@State private var confirmSearch: Bool = false |
|
|
|
|
@State private var locationRequested = false |
|
|
|
|
|
|
|
|
|
var tournaments: [FederalTournament] { |
|
|
|
|
federalDataViewModel.searchedFederalTournaments |
|
|
|
|
@ -96,8 +98,9 @@ struct TournamentLookUpView: View { |
|
|
|
|
.navigationTitle("Chercher un tournoi") |
|
|
|
|
.navigationBarTitleDisplayMode(.inline) |
|
|
|
|
.onChange(of: locationManager.city) { |
|
|
|
|
if let newValue = locationManager.city, dataStore.appSettings.city.isEmpty { |
|
|
|
|
if locationRequested, let newValue = locationManager.city { |
|
|
|
|
dataStore.appSettings.city = newValue |
|
|
|
|
locationRequested = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.toolbarTitleDisplayMode(.large) |
|
|
|
|
@ -309,19 +312,32 @@ struct TournamentLookUpView: View { |
|
|
|
|
|
|
|
|
|
HStack { |
|
|
|
|
TextField("Ville", text: $appSettings.city) |
|
|
|
|
if let city = locationManager.city { |
|
|
|
|
Divider() |
|
|
|
|
Text(city).italic() |
|
|
|
|
} |
|
|
|
|
.onSubmit(of: .text) { |
|
|
|
|
locationManager.city = nil |
|
|
|
|
locationManager.location = nil |
|
|
|
|
} |
|
|
|
|
.focused($isFocused) |
|
|
|
|
.onChange(of: isFocused) { |
|
|
|
|
if isFocused { |
|
|
|
|
appSettings.city = "" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if let city = locationManager.city { |
|
|
|
|
// Divider() |
|
|
|
|
// Text(city).italic() |
|
|
|
|
// } |
|
|
|
|
if locationManager.requestStarted { |
|
|
|
|
ProgressView() |
|
|
|
|
} else if locationManager.manager.authorizationStatus != .restricted { |
|
|
|
|
LocationButton { |
|
|
|
|
if locationManager.manager.authorizationStatus == .notDetermined { |
|
|
|
|
locationRequested = true |
|
|
|
|
locationManager.manager.requestWhenInUseAuthorization() |
|
|
|
|
} else if locationManager.manager.authorizationStatus == .denied { |
|
|
|
|
showingSettingsAlert = true |
|
|
|
|
} else { |
|
|
|
|
locationRequested = true |
|
|
|
|
locationManager.requestLocation() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|