33 lines
675 B
Svelte
33 lines
675 B
Svelte
<script lang="ts">
|
|
import { _ } from 'svelte-i18n';
|
|
import { onMount } from 'svelte';
|
|
import { weatherInfo } from './weather.store';
|
|
let loading = true;
|
|
|
|
function fetchData() {
|
|
loading = true;
|
|
fetch('https://home.lunasqu.ee/api/weather/')
|
|
.then((res) => res.json())
|
|
.then((data) => {
|
|
weatherInfo.set(data);
|
|
loading = false;
|
|
});
|
|
}
|
|
|
|
onMount(() => {
|
|
const timer = setInterval(() => fetchData(), 60000);
|
|
fetchData();
|
|
return () => clearInterval(timer);
|
|
});
|
|
</script>
|
|
|
|
<div class="loading">
|
|
{#if loading}<span>{$_('loading')}</span>{/if}
|
|
</div>
|
|
|
|
<style lang="scss">
|
|
.loading {
|
|
color: #ddd;
|
|
}
|
|
</style>
|