Read workout from url#hash when provided
This commit is contained in:
parent
0638b04921
commit
aa992f43b5
|
|
@ -13,9 +13,21 @@ FreeRide: 20:00
|
|||
Cooldown: 10:00 70%..30%
|
||||
`;
|
||||
|
||||
export const loadWorkout = (): string => {
|
||||
const loadFromUrlHash = (): string | undefined => {
|
||||
if (document.location.hash) {
|
||||
// Skip the leading '#' when decoding
|
||||
return decodeURIComponent(document.location.hash.slice(1));
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const loadFromLocalStorage = (): string | undefined => {
|
||||
const text = localStorage.getItem("workout-editor-text");
|
||||
return (!text || text.trim() === "") ? defaultWorkout : text;
|
||||
return !text || text.trim() === "" ? undefined : text;
|
||||
};
|
||||
|
||||
export const loadWorkout = (): string => {
|
||||
return loadFromUrlHash() ?? loadFromLocalStorage() ?? defaultWorkout;
|
||||
};
|
||||
|
||||
export const saveWorkout = (text: string) => localStorage.setItem("workout-editor-text", text);
|
||||
|
|
|
|||
Loading…
Reference in New Issue