conserve radius of location between Home page & Search page - #1850

This commit is contained in:
Laurent GAY
2025-10-07 16:50:38 +02:00
parent c2dff26afa
commit 9886931f97
3 changed files with 42 additions and 3 deletions

View File

@@ -64,6 +64,7 @@ export const storeAddressInLocal = (address: IAddress | null): undefined => {
window.localStorage.setItem("address", JSON.stringify(address));
} else {
window.localStorage.removeItem("address");
storeRadiusInLocal(null);
}
};
@@ -79,6 +80,24 @@ export const getAddressFromLocal = (): IAddress | null => {
return address;
};
export const storeRadiusInLocal = (
radius: number | null | undefined
): undefined => {
if (radius) {
window.localStorage.setItem("radius", JSON.stringify(radius));
} else {
window.localStorage.removeItem("radius");
}
};
export const getRadiusFromLocal = (): number | null => {
const radiusString = window.localStorage.getItem("radius");
if (!radiusString) {
return null;
}
return JSON.parse(radiusString) as number;
};
export const storeUserLocationAndRadiusFromUserSettings = (
location: IUserPreferredLocation | null
): undefined => {
@@ -91,6 +110,7 @@ export const storeUserLocationAndRadiusFromUserSettings = (
description: location.name || "",
type: "administrative",
});
storeRadiusInLocal(location.range);
}
} else {
console.debug("user has not set a location");