-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add location hash controlled settings (#157)
Resolves #156 Allows certain User settings to be overridden via URL hash parameters. userSlice initialState will attempt to fetch values from URL hash, then fall back to localStorage or defaults. Example usage: ``` http://localhost:5173/29.352,-95.460#user-altitude=MSL&user-speed-unit=m/s&user-temperature-unit=%C2%B0C&user-height-unit=m&user-time-format=12-hour&user-distance-unit=km ```
- Loading branch information
1 parent
92491b5
commit ac15779
Showing
5 changed files
with
149 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const LOCATIONS_STORAGE_KEY = "user-locations"; | ||
export const ALTITUDE_STORAGE_KEY = "user-altitude"; | ||
export const ALTITUDE_LEVELS_STORAGE_KEY = "user-altitude-levels"; | ||
export const HEIGHT_UNIT_STORAGE_KEY = "user-height-unit"; | ||
export const SPEED_UNIT_STORAGE_KEY = "user-speed-unit"; | ||
export const TEMPERATURE_UNIT_STORAGE_KEY = "user-temperature-unit"; | ||
export const DISTANCE_UNIT_STORAGE_KEY = "user-distance-unit"; | ||
export const TIME_FORMAT_STORAGE_KEY = "user-time-format"; | ||
export const DISCUSSION_LAST_VIEWED_STORAGE_KEY = "discussion-last-viewed"; | ||
export const READ_ALERTS = "read-alerts"; | ||
export const HIDDEN_ALERTS = "hidden-alerts"; | ||
export const SWIPE_INERTIA_STORAGE_KEY = "swipe-inertia"; | ||
export const G_AIRMET_READ_STORAGE_KEY = "g-airmet-read"; | ||
export const LANGUAGE_STORAGE_KEY = "user-language"; | ||
export const ADVANCED_STORAGE_KEY = "advanced-mode"; | ||
export const MAX_LOCATIONS = 5; | ||
export const MAX_DISTANCE_MATCH = 1000; // meters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { | ||
ALTITUDE_STORAGE_KEY, | ||
ALTITUDE_LEVELS_STORAGE_KEY, | ||
HEIGHT_UNIT_STORAGE_KEY, | ||
SPEED_UNIT_STORAGE_KEY, | ||
TEMPERATURE_UNIT_STORAGE_KEY, | ||
DISTANCE_UNIT_STORAGE_KEY, | ||
TIME_FORMAT_STORAGE_KEY, | ||
} from "./constants"; | ||
|
||
import { | ||
AltitudeType, | ||
AltitudeLevels, | ||
HeightUnit, | ||
SpeedUnit, | ||
TemperatureUnit, | ||
DistanceUnit, | ||
TimeFormat, | ||
} from "../rap/extra/settings/settingEnums"; | ||
|
||
const locationHashArray = document.location.hash | ||
.replace(/#/, "") | ||
.split(/&/) | ||
.map((kv) => { | ||
const [k, v] = kv.split(/=/); | ||
return [k, decodeURI(v)] as const; | ||
}); | ||
|
||
const locationHashMap: Map<string, string> = new Map(locationHashArray); | ||
|
||
export function getAltitude() { | ||
const value = locationHashMap.get(ALTITUDE_STORAGE_KEY) as AltitudeType; | ||
if ( | ||
value !== AltitudeType.AGL && | ||
value !== AltitudeType.MSL && | ||
value !== AltitudeType.Pressure | ||
) | ||
return undefined; | ||
return value; | ||
} | ||
|
||
export function getAltitudeLevels() { | ||
const value = locationHashMap.get( | ||
ALTITUDE_LEVELS_STORAGE_KEY, | ||
) as AltitudeLevels; | ||
if (value !== AltitudeLevels.Default && value !== AltitudeLevels.Normalized) | ||
return undefined; | ||
return value; | ||
} | ||
|
||
export function getHeightUnit() { | ||
const value = locationHashMap.get(HEIGHT_UNIT_STORAGE_KEY) as HeightUnit; | ||
if (value !== HeightUnit.Feet && value !== HeightUnit.Meters) | ||
return undefined; | ||
return value; | ||
} | ||
|
||
export function getSpeedUnit() { | ||
const value = locationHashMap.get(SPEED_UNIT_STORAGE_KEY) as SpeedUnit; | ||
if ( | ||
value !== SpeedUnit.KPH && | ||
value !== SpeedUnit.Knots && | ||
value !== SpeedUnit.MPH && | ||
value !== SpeedUnit.mps | ||
) | ||
return undefined; | ||
return value; | ||
} | ||
|
||
export function getTemperatureUnit() { | ||
const value = locationHashMap.get( | ||
TEMPERATURE_UNIT_STORAGE_KEY, | ||
) as TemperatureUnit; | ||
if (value !== TemperatureUnit.Celsius && value !== TemperatureUnit.Fahrenheit) | ||
return undefined; | ||
return value; | ||
} | ||
|
||
export function getDistanceUnit() { | ||
const value = locationHashMap.get(DISTANCE_UNIT_STORAGE_KEY) as DistanceUnit; | ||
if (value !== DistanceUnit.Kilometers && value !== DistanceUnit.Miles) | ||
return undefined; | ||
return value; | ||
} | ||
|
||
export function getTimeFormat() { | ||
const value = locationHashMap.get(TIME_FORMAT_STORAGE_KEY) as TimeFormat; | ||
if (value !== TimeFormat.Twelve && value !== TimeFormat.TwentyFour) | ||
return undefined; | ||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters