import './styles/app.scss'; import htmx from 'htmx.org'; window.htmx = htmx; document.addEventListener('click', (event) => { const button = event.target.closest('[data-weather-location]'); if (!button) return; const status = document.querySelector('[data-weather-location-status]'); if (!navigator.geolocation) { if (status) status.textContent = 'Your browser does not support location services.'; return; } navigator.geolocation.getCurrentPosition(async ({coords}) => { const payload = new URLSearchParams({ _token: button.dataset.locationToken, latitude: String(coords.latitude), longitude: String(coords.longitude), }); const response = await fetch(button.dataset.locationUrl, { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: payload, }); if (!response.ok) { if (status) status.textContent = 'Location could not be saved.'; return; } window.location.reload(); }, () => { if (status) status.textContent = 'Location permission was not granted.'; }); });