diff --git a/src/App.vue b/src/App.vue index d5522b6..23529e0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -70,7 +70,9 @@ export default defineComponent({ currentLang: 'pl', releaseURL: '', - isOnProductionHost: location.hostname == 'stacjownik-td2.web.app' + isOnProductionHost: location.hostname == 'stacjownik-td2.web.app', + + nextUpdateTime: 0 }), created() { @@ -78,11 +80,11 @@ export default defineComponent({ }, async mounted() { - window.addEventListener('focus', () => { - if (Date.now() - this.apiStore.lastFetchData.getTime() < 15000) return; + // window.addEventListener('focus', () => { + // if (Date.now() - this.apiStore.lastFetchData.getTime() < 15000) return; - this.apiStore.fetchActiveData(); - }); + // this.apiStore.fetchActiveData(); + // }); window.addEventListener('mousemove', (e: MouseEvent) => this.handlePopUpEvents(e)); }, @@ -95,10 +97,19 @@ export default defineComponent({ this.checkAppVersion(); this.apiStore.setupAPIData(); + window.requestAnimationFrame(this.update); if (!this.isOnProductionHost) document.title = 'Stacjownik Dev'; }, + update(t: number) { + if (t >= this.nextUpdateTime) { + this.apiStore.fetchActiveData(); + this.nextUpdateTime = t + 20000; + } + window.requestAnimationFrame(this.update); + }, + checkAppVersion() { if (import.meta.env.DEV) { this.store.isNewUpdate = true; diff --git a/src/store/apiStore.ts b/src/store/apiStore.ts index b0add55..17e49ef 100644 --- a/src/store/apiStore.ts +++ b/src/store/apiStore.ts @@ -54,18 +54,6 @@ export const useApiStore = defineStore('apiStore', { // Static data this.fetchDonatorsData(); this.fetchStationsGeneralInfo(); - - // Active data schedueler - this.fetchActiveData(); - // this.setupActiveDataFetcher(); - }, - - async setupActiveDataFetcher() { - if (this.activeDataScheduler) return; - - this.activeDataScheduler = window.setInterval(() => { - this.fetchActiveData(); - }, 25000); }, async fetchActiveData() { @@ -75,7 +63,6 @@ export const useApiStore = defineStore('apiStore', { console.log('Fetching active data at ' + new Date().toLocaleTimeString('pl-PL')); const response = await this.client!.get('api/getActiveData'); - console.log(response); this.activeData = response.data; this.lastFetchData = new Date();