mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
chore: offline & fetching fixes
This commit is contained in:
@@ -19,7 +19,6 @@
|
|||||||
<link rel="manifest" href="/site.webmanifest" />
|
<link rel="manifest" href="/site.webmanifest" />
|
||||||
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
|
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
|
||||||
<meta name="msapplication-TileColor" content="#da532c" />
|
<meta name="msapplication-TileColor" content="#da532c" />
|
||||||
<meta name="theme-color" content="#222222" />
|
|
||||||
|
|
||||||
<link rel="icon" href="favicon.ico" />
|
<link rel="icon" href="favicon.ico" />
|
||||||
|
|
||||||
|
|||||||
+5
-15
@@ -81,9 +81,7 @@ export default defineComponent({
|
|||||||
isUpdateCardOpen: false,
|
isUpdateCardOpen: false,
|
||||||
|
|
||||||
currentLang: 'pl',
|
currentLang: 'pl',
|
||||||
isOnProductionHost: location.hostname == 'stacjownik-td2.web.app',
|
isOnProductionHost: location.hostname == 'stacjownik-td2.web.app'
|
||||||
|
|
||||||
nextUpdateTime: 0
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
@@ -96,22 +94,13 @@ export default defineComponent({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
|
if (!this.isOnProductionHost) document.title = 'Stacjownik Dev';
|
||||||
|
|
||||||
this.loadLang();
|
this.loadLang();
|
||||||
this.setupOfflineHandling();
|
this.setupOfflineHandling();
|
||||||
this.checkAppVersion();
|
this.checkAppVersion();
|
||||||
|
|
||||||
this.apiStore.setupAPIData();
|
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);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async checkAppVersion() {
|
async checkAppVersion() {
|
||||||
@@ -131,7 +120,7 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.isUpdateCardOpen =
|
this.isUpdateCardOpen =
|
||||||
(storageVersion != '' && storageVersion != version) ||
|
(storageVersion != '' && storageVersion != version && this.isOnProductionHost) ||
|
||||||
import.meta.env.VITE_UPDATE_TEST === 'test';
|
import.meta.env.VITE_UPDATE_TEST === 'test';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Wystąpił błąd podczas pobierania danych z API GitHuba: ${error}`);
|
console.error(`Wystąpił błąd podczas pobierania danych z API GitHuba: ${error}`);
|
||||||
@@ -158,6 +147,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
handleOnlineMode() {
|
handleOnlineMode() {
|
||||||
this.store.isOffline = false;
|
this.store.isOffline = false;
|
||||||
|
this.apiStore.dataStatuses.connection = Status.Data.Loading;
|
||||||
|
|
||||||
this.apiStore.connectToAPI();
|
this.apiStore.connectToAPI();
|
||||||
},
|
},
|
||||||
|
|||||||
+22
-17
@@ -18,7 +18,7 @@ export const useApiStore = defineStore('apiStore', {
|
|||||||
donatorsData: [] as API.Donators.Response,
|
donatorsData: [] as API.Donators.Response,
|
||||||
sceneryData: [] as StationJSONData[],
|
sceneryData: [] as StationJSONData[],
|
||||||
|
|
||||||
lastFetchData: new Date(),
|
nextUpdateTime: 0,
|
||||||
|
|
||||||
client: undefined as AxiosInstance | undefined,
|
client: undefined as AxiosInstance | undefined,
|
||||||
|
|
||||||
@@ -51,27 +51,33 @@ export const useApiStore = defineStore('apiStore', {
|
|||||||
// Static data
|
// Static data
|
||||||
this.fetchDonatorsData();
|
this.fetchDonatorsData();
|
||||||
this.fetchStationsGeneralInfo();
|
this.fetchStationsGeneralInfo();
|
||||||
|
|
||||||
// Ponowne pobieranie danych po ServiceWorkerze
|
|
||||||
setTimeout(() => {
|
|
||||||
this.fetchStationsGeneralInfo();
|
|
||||||
}, Math.floor(Math.random() * 500) + 1000);
|
|
||||||
|
|
||||||
this.fetchVehiclesInfo();
|
this.fetchVehiclesInfo();
|
||||||
|
|
||||||
|
window.requestAnimationFrame(this.updateTick);
|
||||||
|
},
|
||||||
|
|
||||||
|
updateTick(t: number) {
|
||||||
|
if (this.dataStatuses.connection == Status.Data.Offline) return;
|
||||||
|
|
||||||
|
if (t >= this.nextUpdateTime) {
|
||||||
|
this.fetchActiveData();
|
||||||
|
this.nextUpdateTime = t + 20000;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.requestAnimationFrame(this.updateTick);
|
||||||
},
|
},
|
||||||
|
|
||||||
async fetchActiveData() {
|
async fetchActiveData() {
|
||||||
if (import.meta.env.VITE_API_ACTIVE_DATA_MODE == 'mocking') {
|
// if (import.meta.env.VITE_API_ACTIVE_DATA_MODE == 'mocking') {
|
||||||
import('../../tests/data/getActiveData.json').then((data) => {
|
// import('../../tests/data/getActiveData.json').then((data) => {
|
||||||
console.warn('activeData: mocking mode');
|
// console.warn('activeData: mocking mode');
|
||||||
this.activeData = data.default as API.ActiveData.Response;
|
// this.activeData = data.default as API.ActiveData.Response;
|
||||||
this.lastFetchData = new Date();
|
|
||||||
|
|
||||||
this.dataStatuses.connection = Status.Data.Loaded;
|
// this.dataStatuses.connection = Status.Data.Loaded;
|
||||||
});
|
// });
|
||||||
|
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!this.activeData) this.dataStatuses.connection = Status.Data.Loading;
|
if (!this.activeData) this.dataStatuses.connection = Status.Data.Loading;
|
||||||
|
|
||||||
@@ -79,7 +85,6 @@ export const useApiStore = defineStore('apiStore', {
|
|||||||
const response = await this.client!.get<API.ActiveData.Response>('api/getActiveData');
|
const response = await this.client!.get<API.ActiveData.Response>('api/getActiveData');
|
||||||
|
|
||||||
this.activeData = response.data;
|
this.activeData = response.data;
|
||||||
this.lastFetchData = new Date();
|
|
||||||
this.dataStatuses.connection = Status.Data.Loaded;
|
this.dataStatuses.connection = Status.Data.Loaded;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.dataStatuses.connection = Status.Data.Error;
|
this.dataStatuses.connection = Status.Data.Error;
|
||||||
|
|||||||
Reference in New Issue
Block a user