Add preferences and privacy policy

This commit is contained in:
2026-05-16 21:06:29 +01:00
parent 07579310b2
commit 631d324cba
10 changed files with 457 additions and 17 deletions

View File

@@ -1,12 +1,15 @@
import { OwlClient, ValidationError, ApiError } from './owlClient';
import type { ApiStationsNearestStations } from '@owlboard/owlboard-ts';
import { prefs } from './preferences.svelte';
class NearestStationsState {
list = $state<ApiStationsNearestStations.StationsNearestStations[]>([]);
currentHash = $state('');
loading = $state(true);
loading = $state(false);
error = $state<string | null>(null);
private watcherId: number | null = null;
private initGeoConfig: PositionOptions = {
enableHighAccuracy: false,
timeout: 500,
@@ -20,10 +23,35 @@ class NearestStationsState {
};
constructor() {
if (typeof window !== 'undefined' && 'geolocation' in navigator) {
this.jumpstart();
this.initWatcher();
if (typeof window === 'undefined' || !('geolocation' in navigator)) return;
$effect.root(() => {
$effect(() => {
if (prefs.current.NearToMe) {
this.startTracking();
} else {
this.stopTracking();
}
});
});
}
private startTracking() {
if (this.watcherId !== null) return; // Already tracking
this.loading = true;
this.jumpstart();
this.initWatcher();
}
private stopTracking() {
if (this.watcherId !== null) {
navigator.geolocation.clearWatch(this.watcherId);
this.watcherId = null;
}
this.list = [];
this.currentHash = '';
this.loading = false;
this.error = null;
}
private jumpstart() {
@@ -35,7 +63,7 @@ class NearestStationsState {
}
private initWatcher() {
navigator.geolocation.watchPosition(
this.watcherId = navigator.geolocation.watchPosition(
(pos) => this.handleUpdate(pos.coords.latitude, pos.coords.longitude),
(err) => this.handleError(err),
this.geoConfig