diff --git a/index.html b/index.html index 6f30b69..7036400 100644 --- a/index.html +++ b/index.html @@ -6,9 +6,6 @@ Portal del Cliente - IntegraRepara - - - @@ -81,16 +82,12 @@ : 'https://integrarepara-api.integrarepara.es'; let urlToken = ""; - let mapsToInit = []; - let liveMaps = {}; - let liveMarkers = {}; document.addEventListener("DOMContentLoaded", async () => { lucide.createIcons(); const urlParams = new URLSearchParams(window.location.search); urlToken = urlParams.get('token'); - // CORRECCIÓN: Si no hay token, llamamos a showError() if (!urlToken) { showError(); return; @@ -103,11 +100,10 @@ renderPortal(data.client, data.company, data.services); } catch (e) { console.error(e); - showError(); // CORRECCIÓN: Si falla la conexión o el token es falso, también mostramos error + showError(); } }); - // FUNCIÓN DE ERROR RESTAURADA function showError() { const loader = document.getElementById('loader'); const errorScreen = document.getElementById('errorScreen'); @@ -177,29 +173,25 @@ `; } else if (srv.status_name === 'Técnico de Camino') { + // NUEVO DISEÑO ANIMADO Y LIMPIO PARA "DE CAMINO" SIN MAPA statusHtml = `
-
-
- -
-
-

¡Técnico en camino!

-

Sigue su ubicación en tiempo real.

-
+
+
-
-
-
- -

Buscando satélites...

-
+
+
+ +
+
+

En ruta hacia tu domicilio

+

¡Técnico en camino!

+

Prepárate, el técnico está a punto de llegar a tu ubicación.

`; - mapsToInit.push(srv.id); } else if (srv.status_name === 'En Reparación') { statusHtml = ` @@ -262,56 +254,8 @@ setTimeout(() => { document.getElementById('loader').classList.add('hidden'); document.getElementById('mainContent').classList.remove('hidden'); - - mapsToInit.forEach(id => initLiveMap(id)); }, 300); } - - function initLiveMap(serviceId) { - if(!document.getElementById(`liveMap-${serviceId}`)) return; - - liveMaps[serviceId] = L.map(`liveMap-${serviceId}`, { zoomControl: false, attributionControl: false }).setView([40.416775, -3.703790], 6); - L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png').addTo(liveMaps[serviceId]); - - const carIcon = L.divIcon({ - className: 'custom-div-icon', - html: `
`, - iconSize: [20, 20], - iconAnchor: [10, 10] - }); - - liveMarkers[serviceId] = L.marker([40.416775, -3.703790], {icon: carIcon}); - - fetchWorkerLocation(serviceId); - setInterval(() => fetchWorkerLocation(serviceId), 10000); - } - - async function fetchWorkerLocation(serviceId) { - try { - const res = await fetch(`${API_URL}/public/portal/${urlToken}/location/${serviceId}`); - const data = await res.json(); - - if (data.ok && data.location) { - const loader = document.getElementById(`map-loader-${serviceId}`); - if(loader) loader.classList.add('hidden'); - - const lat = parseFloat(data.location.lat); - const lng = parseFloat(data.location.lng); - - if (!liveMaps[serviceId].hasLayer(liveMarkers[serviceId])) { - liveMarkers[serviceId].addTo(liveMaps[serviceId]); - liveMaps[serviceId].setView([lat, lng], 15); - } else { - liveMarkers[serviceId].setLatLng([lat, lng]); - liveMaps[serviceId].flyTo([lat, lng], 16, { animate: true, duration: 1.5 }); - } - } else { - // MEJORA: Mensaje claro si el técnico no ha encendido su GPS todavía - const p = document.querySelector(`#map-loader-${serviceId} p`); - if(p) p.innerText = "ESPERANDO SEÑAL GPS DEL TÉCNICO..."; - } - } catch(e) {} - } \ No newline at end of file