This repository has been archived on 2026-08-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
drizzli/src/lib/stores/settings.ts
T

126 lines
3.6 KiB
TypeScript

import { persisted } from 'svelte-persisted-store';
export interface GeoLocation {
id: number;
name: string;
latitude: number;
longitude: number;
elevation: number;
feature_code: string;
country_code: string | undefined;
admin1_id: number | undefined;
admin3_id?: number | undefined;
admin4_id?: number | undefined;
timezone: string;
population: number | undefined;
postcodes: string[] | undefined;
country_id: number | undefined;
country: string | undefined;
admin1: string | undefined;
admin3?: string | undefined;
admin4?: string | undefined;
}
export const defaultLocation: GeoLocation = {
id: 2950159,
name: 'Berlin',
latitude: 52.52437,
longitude: 13.41053,
elevation: 74,
feature_code: 'PPLC',
country_code: 'DE',
admin1_id: 2950157,
admin3_id: 6547383,
admin4_id: 6547539,
timezone: 'Europe/Berlin',
population: 3426354,
postcodes: ['10967', '13347'],
country_id: 2921044,
country: 'Germany',
admin1: 'Land Berlin',
admin3: 'Berlin, Stadt',
admin4: 'Berlin'
};
export const storedLocation = persisted('stored_location', defaultLocation as GeoLocation);
export type Theme = 'system' | 'light' | 'dark';
export const storedTheme = persisted<Theme>('theme', 'system');
/** Selected forecast model, shared across the whole site. */
export const storedModel = persisted<string>('selected_model', 'best_match');
/** Which variables are visible in the hourly table and the meteograms. */
export interface VariablePrefs {
table: Record<string, boolean>;
charts: Record<string, boolean>;
}
export const defaultVariablePrefs: VariablePrefs = {
table: {
icons: true,
temperature: true,
feels: true,
wind: true,
humidity: true,
clouds: true,
precipitation: true
},
charts: {
temperature: true,
cloud_cover: true,
precipitation: true,
precipitation_probability: true,
wind: true,
humidity: true
}
};
export const storedVariablePrefs = persisted<VariablePrefs>('variable_prefs', defaultVariablePrefs);
/**
* Meteogram layout: an ordered list of chart panels, each holding an ordered
* list of variable keys (see the chart variable registry). Users drag
* variables between panels to fully customise the meteograms.
*/
export interface ChartPanel {
id: string;
variables: string[];
}
export const defaultChartLayout: ChartPanel[] = [
{ id: 'panel-1', variables: ['weather_icons', 'temperature', 'cloud_cover'] },
{ id: 'panel-2', variables: ['precipitation', 'precipitation_probability'] },
{ id: 'panel-3', variables: ['wind', 'humidity'] }
];
export const storedChartLayout = persisted<ChartPanel[]>('chart_layout_v1', defaultChartLayout);
/** Selected ensemble model for the 14-day spread forecast. */
export const storedEnsembleModel = persisted<string>('ensemble_model', 'ncep_gefs_seamless');
/** Measurement units, shared across every forecast page and persisted. */
export interface UnitPrefs {
temperature_unit: 'celsius' | 'fahrenheit';
wind_speed_unit: 'kmh' | 'ms' | 'mph' | 'kn';
precipitation_unit: 'mm' | 'inch';
}
export const defaultUnits: UnitPrefs = {
temperature_unit: 'celsius',
wind_speed_unit: 'kmh',
precipitation_unit: 'mm'
};
export const storedUnits = persisted<UnitPrefs>('units_v1', defaultUnits);
/** Recently visited and starred locations, shown in the search dropdown. */
export const storedRecentLocations = persisted<GeoLocation[]>('recent_locations_v1', []);
export const storedFavoriteLocations = persisted<GeoLocation[]>('favorite_locations_v1', []);
/** Stable key for de-duping locations (geocoding id, or rounded coordinates). */
export function locationKey(l: GeoLocation): string {
return l.id && l.id !== 0 ? `id:${l.id}` : `c:${l.latitude.toFixed(3)},${l.longitude.toFixed(3)}`;
}