2 import PageLink from './PageLink.svelte';
3 import * as timeago from 'timeago.js';
4 import { last_api_request_url_store } from '../lib/stores.js';
5 import { fetch_from_api } from '../lib/api_utils.js';
8 let last_api_request_url;
9 let fetch_running = false; // prevent multiple parallel fetch runs
11 last_api_request_url_store.subscribe(url => {
12 last_api_request_url = url;
14 if (last_api_request_url) {
15 last_api_request_url = new URL(last_api_request_url, window.location.origin);
16 last_api_request_url.searchParams.delete('polygon_geojson');
17 last_api_request_url = last_api_request_url.toString();
20 if (fetch_running || last_updated_date) return;
24 fetch_from_api('status', { format: 'json' }, function (data) {
25 last_updated_date = data.data_updated;
26 fetch_running = false;
44 background-color: #eee;
49 <div id="last-updated" class="container-fluid py-2 px-4 mb-3">
50 <div id="loading" class="py-2 px-4">
51 <div class="spinner-border spinner-border-sm text-primary me-1" role="status"></div>
52 Loading data from API ...
55 <div class="col-sm-6">
56 {#if last_api_request_url}
57 <div id="api-request">
58 Data from <a href="{last_api_request_url}">API request</a>
59 <span id="api-request-debug">
60 (<a href="{last_api_request_url}&debug=1">debug output</a>)
65 <div class="col-sm-6 text-end">
66 {#if last_updated_date}
68 <abbr id="data-date" title="{last_updated_date} (UTC timezone)">{timeago.format(new Date(last_updated_date))}</abbr>
70 (<PageLink page="status">Details</PageLink>)