diff --git a/package.json b/package.json index eb3f4ad..4ab8123 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stacjownik", - "version": "1.22.1", + "version": "1.22.2", "private": true, "scripts": { "dev": "vite", diff --git a/src/App.vue b/src/App.vue index 3ea335e..e038a36 100644 --- a/src/App.vue +++ b/src/App.vue @@ -73,6 +73,12 @@ export default defineComponent({ }, async mounted() { + window.addEventListener('focus', () => { + if (Date.now() - this.apiStore.lastFetchData.getTime() < 15000) return; + + this.apiStore.fetchActiveData(); + }); + watch( () => this.store.blockScroll, (value) => { diff --git a/src/store/apiStore.ts b/src/store/apiStore.ts index 49de11a..1fa0166 100644 --- a/src/store/apiStore.ts +++ b/src/store/apiStore.ts @@ -24,6 +24,8 @@ export const useApiStore = defineStore('apiStore', { donatorsData: [] as API.Donators.Response, sceneryData: [] as StationJSONData[], + lastFetchData: new Date(), + client: undefined as AxiosInstance | undefined, activeDataScheduler: undefined as number | undefined @@ -64,20 +66,19 @@ export const useApiStore = defineStore('apiStore', { async setupActiveDataFetcher() { if (this.activeDataScheduler) return; - this.dataStatuses.connection = Status.Data.Loading; - this.activeDataScheduler = window.setInterval(() => { - if (UPDATE_SECONDS.includes(new Date().getSeconds())) { - this.fetchActiveData(); - } - }, 1000); + this.fetchActiveData(); + }, 25000); }, async fetchActiveData() { + if (!this.activeData) this.dataStatuses.connection = Status.Data.Loading; + try { const response = await this.client!.get('api/getActiveData'); this.activeData = response.data; + this.lastFetchData = new Date(); this.dataStatuses.connection = Status.Data.Loaded; console.log('Fetching active data at ' + new Date().toLocaleTimeString('pl-PL'));