svelte-ts/src/routes/temps/+page.svelte

61 líneas
1,8 KiB
Svelte
Original Vista normal Històric

2023-02-03 15:06:55 +01:00
<script lang="ts">
import { enhance } from "$app/forms";
let display: string = 'none';
2023-02-06 21:25:31 +01:00
let loading: boolean = false;
2023-02-03 15:06:55 +01:00
export let data: any;
function toggleDisplay(): void {
display = (display === 'none') ? 'block' : 'none';
}
2023-02-06 13:04:36 +01:00
2023-02-06 21:25:31 +01:00
// $: variables = data.weatherData.dies[0].variables;
2023-02-03 15:06:55 +01:00
</script>
<div class="box" id="locChange" style="display: {display};">
2023-02-06 21:25:31 +01:00
<form action="?/changeLoc" method="post" use:enhance={ () => { loading = true; return async ( { update } ) => { await update(); loading = false; } } }>
2023-02-03 15:06:55 +01:00
<p>Change location</p>
2023-02-06 21:25:31 +01:00
<div class="schBox"><input type="text" placeholder="Change location" name='newloc' disabled={ loading }></div>
<button type="submit" disabled={loading}>Canviar</button>
2023-02-03 15:06:55 +01:00
</form>
</div>
2023-02-06 13:04:36 +01:00
<button type="button" on:click={toggleDisplay}>Canviar ubicació</button>
<p>El temps a: {data.location}</p>
2023-02-06 21:25:31 +01:00
<pre>{ JSON.stringify(data.weatherData) }</pre>
2023-02-06 13:04:36 +01:00
<table>
<thead>
<tr>
<th>Temperatura màxima</th>
<th>Temperatura mínima</th>
<th>Precipitació</th>
</tr>
</thead>
<tbody>
2023-02-06 21:25:31 +01:00
<!-- <tr>
2023-02-06 13:04:36 +01:00
<td>{ variables.tmax.valor }{ variables.tmax.unitat }</td>
<td>{ variables.tmin.valor }{ variables.tmin.unitat }</td>
<td>{ variables.precipitacio.valor }{ variables.precipitacio.unitat }</td>
2023-02-06 21:25:31 +01:00
</tr> -->
2023-02-06 13:04:36 +01:00
</tbody>
</table>
2023-02-06 21:25:31 +01:00
<pre>{ JSON.stringify(data.openMeteoData) }</pre>
<pre>{ JSON.stringify(data.consums) ?? 'No consum available' }</pre>
<footer>
<p>Dades provinents de:</p>
<ul>
<li><a href='https://meteo.cat' target="_blank" rel="noreferrer">Servei Meteorologic de Catalunya</a></li>
<li><a href='https://open-meteo.com' target="_blank" rel="noreferrer">Open-Meteo</a></li>
</ul>
</footer>
2023-02-06 13:04:36 +01:00
<style>
table {
border-collapse: collapse;
border: 1px solid black;
}
th, td {
border-collapse: collapse;
border: 1px solid black
}
</style>