WIP: weather integration
This commit is contained in:
@@ -2,3 +2,24 @@ 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 || !navigator.geolocation) 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) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user