From a3f704a57d7bb7cd56af3a03049c48c3db95aca5 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 10 Feb 2023 01:35:49 +0100 Subject: [PATCH] Only jump to the start location if no coordinates are given in the URL --- Logic/State/GeoLocationState.ts | 8 +++++++- UI/BigComponents/GeolocationControl.ts | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Logic/State/GeoLocationState.ts b/Logic/State/GeoLocationState.ts index 7184c2e81..b6bd13e24 100644 --- a/Logic/State/GeoLocationState.ts +++ b/Logic/State/GeoLocationState.ts @@ -1,5 +1,6 @@ import { UIEventSource } from "../UIEventSource" import { LocalStorageSource } from "../Web/LocalStorageSource" +import { QueryParameters } from "../Web/QueryParameters" type GeolocationState = "prompt" | "requested" | "granted" | "denied" @@ -79,6 +80,11 @@ export class GeoLocationState { // We set the flag to false again. If the user only wanted to share their location once, we are not gonna keep bothering them this._previousLocationGrant.setData("false") console.log("Requesting access to GPS as this was previously granted") + const latLonGivenViaUrl = + QueryParameters.wasInitialized("lat") || QueryParameters.wasInitialized("lon") + if (!latLonGivenViaUrl) { + this.requestMoment.setData(new Date()) + } this.requestPermission() } window["geolocation_state"] = this @@ -120,7 +126,7 @@ export class GeoLocationState { // Hence that we continue the flow if it is "requested" return } - this.requestMoment.setData(new Date()) + this.permission.setData("requested") try { navigator?.permissions diff --git a/UI/BigComponents/GeolocationControl.ts b/UI/BigComponents/GeolocationControl.ts index 1d1eb6908..9350d252a 100644 --- a/UI/BigComponents/GeolocationControl.ts +++ b/UI/BigComponents/GeolocationControl.ts @@ -91,6 +91,7 @@ export class GeolocationControl extends VariableUiElement { geolocationState.currentGPSLocation.data === undefined ) { lastClick.setData(new Date()) + geolocationState.requestMoment.setData(new Date()) await geolocationState.requestPermission() }