fix pobierania danych

This commit is contained in:
2024-03-16 22:13:38 +01:00
parent 1c9b54b578
commit 084823de44
3 changed files with 14 additions and 7 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "stacjownik",
"version": "1.22.1",
"version": "1.22.2",
"private": true,
"scripts": {
"dev": "vite",
+6
View File
@@ -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) => {
+7 -6
View File
@@ -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.ActiveData.Response>('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'));