aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2022-05-03 00:32:59 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2022-05-03 00:32:59 +0200
commit417ebe16a9573c123538658bae8853199d244b30 (patch)
treea7e7e7667a46c9f949a1cf3e35509a69bdb85fd6 /src/components
parent30b7af1dbec405b02df794a799a24c6f35dfbdc5 (diff)
downloadAurora-data-417ebe16a9573c123538658bae8853199d244b30.tar.gz
Aurora-data-417ebe16a9573c123538658bae8853199d244b30.zip
Add caching of data (currently live-time is 5 minutes)
Diffstat (limited to 'src/components')
-rw-r--r--src/components/WeatherCurrent.svelte26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/components/WeatherCurrent.svelte b/src/components/WeatherCurrent.svelte
index 9c47873..778fb12 100644
--- a/src/components/WeatherCurrent.svelte
+++ b/src/components/WeatherCurrent.svelte
@@ -2,10 +2,29 @@
import SpinnerRoller from './Spinner/SpinnerRoller.svelte';
import { onMount } from 'svelte';
- import { navigator_location, earth_weather, space_weather } from '../stores';
+ import { get } from 'svelte/store';
+ import { data_max_age, navigator_location, earth_weather, space_weather } from '../stores';
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
+
+ let oldestUpdateTime = new Date(0,0,0);
+ let timeagoLastUpdate = 0;
+ function updateOldestUpdateTime() {
+ let earthWeatherUpdate = get(earth_weather).updated;
+ let spaceWeatherUpdate = get(space_weather).updated;
+
+ let now = new Date();
+ if (now - spaceWeatherUpdate > now - earthWeatherUpdate) {
+ oldestUpdateTime = spaceWeatherUpdate;
+ timeagoLastUpdate = now - spaceWeatherUpdate;
+ } else {
+ oldestUpdateTime = earthWeatherUpdate;
+ timeagoLastUpdate = now - earthWeatherUpdate;
+ }
+ }
+
+ setInterval(updateOldestUpdateTime, 500);
</script>
<style>
@@ -108,7 +127,10 @@
{#if Math.abs($earth_weather.updated - $space_weather.updated) > 60*10*1000}
<p>There is more than 10 minutes difference between data updates</p>
{:else}
- <p>{$earth_weather.updated.toLocaleString("no-NO", {dateStyle: "medium", timeStyle: "short"})}</p>
+ <p>{oldestUpdateTime.toLocaleString("no-NO", {dateStyle: "medium", timeStyle: "short"})}</p>
+ {/if}
+ {#if timeagoLastUpdate >= data_max_age}
+ <span style="color:red;"><i class="symbol fas fa-exclamation-circle"></i> Data is {Math.round(timeagoLastUpdate / 60 / 1000)} minutes old!</span>
{/if}
{/if}
</div>