conserve radius of location between Home page & Search page - #1850
This commit is contained in:
@@ -84,7 +84,9 @@ import { AddressSearchType, ContentType } from "@/types/enums";
|
|||||||
import {
|
import {
|
||||||
addressToLocation,
|
addressToLocation,
|
||||||
getAddressFromLocal,
|
getAddressFromLocal,
|
||||||
|
getRadiusFromLocal,
|
||||||
storeAddressInLocal,
|
storeAddressInLocal,
|
||||||
|
storeRadiusInLocal,
|
||||||
} from "@/utils/location";
|
} from "@/utils/location";
|
||||||
import { computed, defineAsyncComponent } from "vue";
|
import { computed, defineAsyncComponent } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
@@ -145,11 +147,20 @@ const search = computed({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const distance = computed({
|
const distance = computed({
|
||||||
get(): number {
|
get(): number | null {
|
||||||
return props.distance;
|
if (props.distance) {
|
||||||
|
return props.distance;
|
||||||
|
}
|
||||||
|
if (props.fromLocalStorage) {
|
||||||
|
return getRadiusFromLocal();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
set(newDistance: number) {
|
set(newDistance: number) {
|
||||||
emit("update:distance", newDistance);
|
emit("update:distance", newDistance);
|
||||||
|
if (props.fromLocalStorage) {
|
||||||
|
storeRadiusInLocal(newDistance);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export const storeAddressInLocal = (address: IAddress | null): undefined => {
|
|||||||
window.localStorage.setItem("address", JSON.stringify(address));
|
window.localStorage.setItem("address", JSON.stringify(address));
|
||||||
} else {
|
} else {
|
||||||
window.localStorage.removeItem("address");
|
window.localStorage.removeItem("address");
|
||||||
|
storeRadiusInLocal(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -79,6 +80,24 @@ export const getAddressFromLocal = (): IAddress | null => {
|
|||||||
return address;
|
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 = (
|
export const storeUserLocationAndRadiusFromUserSettings = (
|
||||||
location: IUserPreferredLocation | null
|
location: IUserPreferredLocation | null
|
||||||
): undefined => {
|
): undefined => {
|
||||||
@@ -91,6 +110,7 @@ export const storeUserLocationAndRadiusFromUserSettings = (
|
|||||||
description: location.name || "",
|
description: location.name || "",
|
||||||
type: "administrative",
|
type: "administrative",
|
||||||
});
|
});
|
||||||
|
storeRadiusInLocal(location.range);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.debug("user has not set a location");
|
console.debug("user has not set a location");
|
||||||
|
|||||||
@@ -193,8 +193,10 @@ import {
|
|||||||
addressToLocation,
|
addressToLocation,
|
||||||
geoHashToCoords,
|
geoHashToCoords,
|
||||||
getAddressFromLocal,
|
getAddressFromLocal,
|
||||||
|
getRadiusFromLocal,
|
||||||
locationToAddress,
|
locationToAddress,
|
||||||
storeAddressInLocal,
|
storeAddressInLocal,
|
||||||
|
storeRadiusInLocal,
|
||||||
} from "@/utils/location";
|
} from "@/utils/location";
|
||||||
import { useServerProvidedLocation } from "@/composition/apollo/config";
|
import { useServerProvidedLocation } from "@/composition/apollo/config";
|
||||||
import QuickPublish from "@/components/Home/QuickPublish.vue";
|
import QuickPublish from "@/components/Home/QuickPublish.vue";
|
||||||
@@ -520,13 +522,19 @@ const distance = computed({
|
|||||||
get(): number | null {
|
get(): number | null {
|
||||||
if (noAddress.value || !userLocation.value?.name) {
|
if (noAddress.value || !userLocation.value?.name) {
|
||||||
return null;
|
return null;
|
||||||
} else if (current_distance.value == null) {
|
}
|
||||||
|
if (current_distance.value == null) {
|
||||||
|
const local_radius = getRadiusFromLocal();
|
||||||
|
if (local_radius) {
|
||||||
|
return local_radius;
|
||||||
|
}
|
||||||
return userLocation.value?.isIPLocation ? 150 : 25;
|
return userLocation.value?.isIPLocation ? 150 : 25;
|
||||||
}
|
}
|
||||||
return current_distance.value;
|
return current_distance.value;
|
||||||
},
|
},
|
||||||
set(newDistance: number) {
|
set(newDistance: number) {
|
||||||
current_distance.value = newDistance;
|
current_distance.value = newDistance;
|
||||||
|
storeRadiusInLocal(newDistance);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user