correction about issue #1556 : Fix location on homepage and location clearing

This commit is contained in:
Laurent GAY 2024-10-23 16:13:17 +02:00
parent 3ed4105879
commit 9403a9d60a
3 changed files with 20 additions and 2 deletions

View file

@ -374,7 +374,7 @@ const asyncData = async (query: string): Promise<void> => {
}; };
const selectedAddressText = computed(() => { const selectedAddressText = computed(() => {
if (!selected) return undefined; if (!selected || !selected.id) return undefined;
return addressFullName(selected); return addressFullName(selected);
}); });

View file

@ -27,6 +27,7 @@
:default-text="locationDefaultText" :default-text="locationDefaultText"
labelClass="sr-only" labelClass="sr-only"
:placeholder="t('e.g. Nantes, Berlin, Cork, …')" :placeholder="t('e.g. Nantes, Berlin, Cork, …')"
v-on:update:modelValue="modelValueUpdate"
/> />
<o-button native-type="submit" icon-left="magnify"> <o-button native-type="submit" icon-left="magnify">
<template v-if="search">{{ t("Go!") }}</template> <template v-if="search">{{ t("Go!") }}</template>
@ -95,6 +96,10 @@ const search = computed({
}, },
}); });
const modelValueUpdate = (newlocation: IAddress | null) => {
emit("update:location", newlocation);
};
const submit = () => { const submit = () => {
emit("submit"); emit("submit");
const { lat, lon } = addressToLocation(location.value); const { lat, lon } = addressToLocation(location.value);

View file

@ -29,7 +29,8 @@
<search-fields <search-fields
v-model:search="search" v-model:search="search"
v-model:location="location" v-model:location="location"
:locationDefaultText="location?.description" :locationDefaultText="location?.description ?? userLocation?.name"
v-on:update:location="updateLocation"
:fromLocalStorage="true" :fromLocalStorage="true"
/> />
<!-- Categories preview --> <!-- Categories preview -->
@ -237,6 +238,7 @@ const currentUserParticipations = computed(
const location = ref(null); const location = ref(null);
const search = ref(""); const search = ref("");
const noLocation = ref(false);
watch(location, (newLoc, oldLoc) => watch(location, (newLoc, oldLoc) =>
console.debug("LOCATION UPDATED from", { ...oldLoc }, " to ", { ...newLoc }) console.debug("LOCATION UPDATED from", { ...oldLoc }, " to ", { ...newLoc })
@ -428,6 +430,13 @@ const currentUserLocation = computed(() => {
const userLocation = computed(() => { const userLocation = computed(() => {
console.debug("new userLocation"); console.debug("new userLocation");
if (noLocation.value) {
return {
lon: null,
lat: null,
name: null,
};
}
if (location.value) { if (location.value) {
console.debug("userLocation is typed location"); console.debug("userLocation is typed location");
return addressToLocation(location.value); return addressToLocation(location.value);
@ -502,6 +511,10 @@ const performGeoLocation = () => {
); );
}; };
const updateLocation = (newlocation: IAddress | null) => {
noLocation.value = newlocation == null;
};
/** /**
* View Head * View Head
*/ */