Fix auth visibility and map user location persistence issues
This commit is contained in:
@ -1,12 +1,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { defineAsyncComponent } from 'vue'
|
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const LoginForm = defineAsyncComponent(() => import('@/components/auth/LoginForm.vue'))
|
import LoginForm from '@/components/auth/LoginForm.vue'
|
||||||
const RegisterForm = defineAsyncComponent(() => import('@/components/auth/RegisterForm.vue'))
|
import RegisterForm from '@/components/auth/RegisterForm.vue'
|
||||||
|
|
||||||
const isLogin = ref(true)
|
const isLogin = ref(true)
|
||||||
const toggleAuth = () => { isLogin.value = !isLogin.value }
|
const toggleAuth = () => { isLogin.value = !isLogin.value }
|
||||||
|
|||||||
@ -253,6 +253,12 @@ async function initializeMap() {
|
|||||||
locateUser();
|
locateUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Si iniciamos con una ruta seleccionada (ej. desde query param),
|
||||||
|
// forzamos el cálculo de la parada óptima si es apropiado
|
||||||
|
if (routeStore.selectedRouteId && routeStore.wasSelectedFromMap) {
|
||||||
|
highlightOptimalStopForRoute();
|
||||||
|
}
|
||||||
|
|
||||||
// Apply initial styles based on current zoom
|
// Apply initial styles based on current zoom
|
||||||
updateMarkersStyles();
|
updateMarkersStyles();
|
||||||
}
|
}
|
||||||
@ -264,7 +270,7 @@ watch(
|
|||||||
// Si la selección no viene de dentro de MapView (selectRouteAndClose),
|
// Si la selección no viene de dentro de MapView (selectRouteAndClose),
|
||||||
// reseteamos el flag de origen Mapa para que el buscador no se "fije"
|
// reseteamos el flag de origen Mapa para que el buscador no se "fije"
|
||||||
if (!isInternalSelection.value) {
|
if (!isInternalSelection.value) {
|
||||||
routeStore.wasSelectedFromMap = false;
|
// routeStore.wasSelectedFromMap = false; // COMENTADO: Mantenemos el flag para que el banner sea persistente si el usuario vuelve
|
||||||
}
|
}
|
||||||
|
|
||||||
// ALWAYS clear markers first when route changes - do this immediately
|
// ALWAYS clear markers first when route changes - do this immediately
|
||||||
@ -281,6 +287,11 @@ watch(
|
|||||||
if (routeStore.wasSelectedFromMap) {
|
if (routeStore.wasSelectedFromMap) {
|
||||||
// Only update map visuals if selection came from the Map search flow
|
// Only update map visuals if selection came from the Map search flow
|
||||||
await updateMapMarkers(true);
|
await updateMapMarkers(true);
|
||||||
|
|
||||||
|
// ASEGURAR que calculamos la parada óptima siempre que se seleccione ruta desde el mapa
|
||||||
|
if (!isInternalSelection.value) {
|
||||||
|
await highlightOptimalStopForRoute();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// If selection came from Schedules or elsewhere, KEEP THE MAP CLEAN
|
// If selection came from Schedules or elsewhere, KEEP THE MAP CLEAN
|
||||||
console.log('Selection from outside Map - clearing map markings');
|
console.log('Selection from outside Map - clearing map markings');
|
||||||
@ -327,6 +338,26 @@ watch(
|
|||||||
// Replaced by useMapState central clearing
|
// Replaced by useMapState central clearing
|
||||||
function clearMapMarkers() {
|
function clearMapMarkers() {
|
||||||
limpiarTodoCentralizado()
|
limpiarTodoCentralizado()
|
||||||
|
// Tras limpiar todo, si tenemos ubicación de usuario, la restauramos
|
||||||
|
// porque el marcador celestre sonar es un overlay que el centralizado elimina
|
||||||
|
if (userCoords.value && authStore.userProfile?.auto_location) {
|
||||||
|
reDrawUserMarker();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function reDrawUserMarker() {
|
||||||
|
if (!userCoords.value) return;
|
||||||
|
|
||||||
|
// Remove old one if exists (paranoia)
|
||||||
|
if (userMarker.value && typeof userMarker.value.setMap === 'function') {
|
||||||
|
userMarker.value.setMap(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
userMarker.value = addHtmlMarker(
|
||||||
|
{ lat: userCoords.value.lat, lng: userCoords.value.lng },
|
||||||
|
sonarHtml,
|
||||||
|
{ x: -30, y: -30 }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateMapMarkers(skipZoom = false) {
|
async function updateMapMarkers(skipZoom = false) {
|
||||||
@ -517,7 +548,11 @@ function locateUser(): Promise<void> {
|
|||||||
*/
|
*/
|
||||||
async function highlightOptimalStopForRoute() {
|
async function highlightOptimalStopForRoute() {
|
||||||
if (!userCoords.value) {
|
if (!userCoords.value) {
|
||||||
|
try {
|
||||||
await locateUser();
|
await locateUser();
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('🤖 JARVIS: Falló la geolocalización automática:', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userCoords.value || routeStore.selectedRouteStops.length === 0) {
|
if (!userCoords.value || routeStore.selectedRouteStops.length === 0) {
|
||||||
@ -527,8 +562,13 @@ async function highlightOptimalStopForRoute() {
|
|||||||
|
|
||||||
console.log('🤖 JARVIS: Calculando punto de abordaje óptimo sobre la ruta mediante calles...');
|
console.log('🤖 JARVIS: Calculando punto de abordaje óptimo sobre la ruta mediante calles...');
|
||||||
|
|
||||||
|
try {
|
||||||
// Encontrar parada real y añadir ruta peatonal azul punteada
|
// Encontrar parada real y añadir ruta peatonal azul punteada
|
||||||
await encontrarParadaCercana(userCoords.value, routeStore.selectedRouteStops as BusStop[], map.value || undefined);
|
await encontrarParadaCercana(userCoords.value, routeStore.selectedRouteStops as BusStop[], map.value || undefined);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('🤖 JARVIS: Error en encontrarParadaCercana:', e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (paradaCercana.value) {
|
if (paradaCercana.value) {
|
||||||
const stopObj = paradaCercana.value as BusStop;
|
const stopObj = paradaCercana.value as BusStop;
|
||||||
@ -656,7 +696,7 @@ async function highlightOptimalStopForRoute() {
|
|||||||
<!-- Nuevo Banner de Parada Cercana Alineado (Redimensionado y con ETA) -->
|
<!-- Nuevo Banner de Parada Cercana Alineado (Redimensionado y con ETA) -->
|
||||||
<Transition name="banner-slide">
|
<Transition name="banner-slide">
|
||||||
<div
|
<div
|
||||||
v-if="paradaCercana && routeStore.selectedRouteId && !showETACard && !isBannerClosing && routeStore.wasSelectedFromMap"
|
v-if="paradaCercana && routeStore.selectedRouteId && !isBannerClosing && routeStore.wasSelectedFromMap"
|
||||||
class="best-stop-banner-compact"
|
class="best-stop-banner-compact"
|
||||||
>
|
>
|
||||||
<div class="banner-icon-bg">
|
<div class="banner-icon-bg">
|
||||||
|
|||||||
Reference in New Issue
Block a user