refactor(stats): moved fetching daily stats data to store

This commit is contained in:
2026-02-18 02:51:33 +01:00
parent 7b07a43715
commit 72fa9523e8
2 changed files with 70 additions and 91 deletions
+19 -1
View File
@@ -9,7 +9,8 @@ export const useApiStore = defineStore('apiStore', {
dataStatuses: {
connection: Status.Data.Loading,
sceneries: Status.Data.Loading,
vehicles: Status.Data.Loading
vehicles: Status.Data.Loading,
dailyStatsData: Status.Data.Loading
},
activeData: undefined as API.ActiveData.Response | undefined,
@@ -18,6 +19,8 @@ export const useApiStore = defineStore('apiStore', {
donatorsData: [] as API.Donators.Response,
sceneryData: [] as StationJSONData[],
dailyStatsData: null as API.DailyStats.Response | null,
nextUpdateTime: 0,
nextDataCheckTime: 0,
@@ -119,6 +122,21 @@ export const useApiStore = defineStore('apiStore', {
this.dataStatuses.vehicles = Status.Data.Error;
console.error('Ups! Wystąpił błąd podczas pobierania informacji o pojazdach:', error);
}
},
async fetchDailyStats() {
try {
const res: API.DailyStats.Response = await (
await this.client!.get('api/getDailyStats')
).data;
this.dailyStatsData = res;
this.dataStatuses.dailyStatsData = Status.Data.Loaded;
} catch (error) {
console.error('Ups! Wystąpił błąd podczas pobierania statystyk rozkładów jazdy...');
this.dataStatuses.dailyStatsData = Status.Data.Error;
}
}
}
});