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

34 líneas
1,2 KiB
Svelte
Original Vista normal Històric

2023-02-06 21:25:31 +01:00
<script lang="ts">
import { enhance } from "$app/forms";
2023-02-25 02:29:18 +01:00
import Graph from "../../lib/graph.svelte";
2023-02-06 21:25:31 +01:00
let display: string = 'none';
let loading: boolean = false;
2023-02-15 16:20:45 +01:00
export let data: { ubicacio: string, temps: any };
2023-02-06 21:25:31 +01:00
function toggleDisplay(): void {
display = (display === 'none') ? 'block' : 'none';
}
</script>
2023-02-25 01:37:57 +01:00
<main>
2023-02-06 21:25:31 +01:00
<div class="box" id="locChange" style="display: {display};">
<form action="?/changeLoc" method="post" use:enhance={ () => { loading = true; return async ( { update } ) => { await update(); loading = false; } } }>
<p>Change location</p>
<div class="schBox"><input type="text" placeholder="Change location" name='newloc' disabled={ loading }></div>
<button type="submit" disabled={loading}>Canviar</button>
</form>
</div>
<h2>Ubicació actual: { data.ubicacio }</h2>
2023-02-06 21:25:31 +01:00
<button type="button" on:click={toggleDisplay}>Canviar ubicació</button>
2023-02-15 12:40:26 +01:00
<pre>{ JSON.stringify(data) }</pre>
2023-02-15 16:20:45 +01:00
<Graph ubicacio={data.ubicacio} series={data.temps} />
2023-02-25 01:37:57 +01:00
</main>
2023-02-06 21:25:31 +01:00
<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>