PWA: tryb offline

This commit is contained in:
2022-12-26 18:43:15 +01:00
parent f93c1fbfec
commit 2e721fb8bf
17 changed files with 2531 additions and 2366 deletions
+11 -4
View File
@@ -17,7 +17,6 @@ import {
} from '../scripts/utils/storeUtils';
import { APIData, StationJSONData, StoreState } from './storeTypes';
export const useStore = defineStore('store', {
state: () =>
({
@@ -35,6 +34,7 @@ export const useStore = defineStore('store', {
stationCount: 0,
webSocket: undefined,
isOffline: false,
dispatcherStatsName: '',
dispatcherStatsData: undefined,
@@ -57,7 +57,6 @@ export const useStore = defineStore('store', {
blockScroll: false,
listenerLaunched: false,
} as StoreState),
actions: {
@@ -225,6 +224,14 @@ export const useStore = defineStore('store', {
const onlineStationNames: string[] = [];
const prevDispatcherStatuses: StoreState['lastDispatcherStatuses'] = [];
if (this.isOffline) {
this.stationList.forEach((station) => {
station.onlineInfo = undefined;
});
return;
}
this.apiData.stations?.forEach((stationAPIData) => {
if (stationAPIData.region !== this.region.id || !stationAPIData.isOnline) return;
const station = this.stationList.find((s) => s.name === stationAPIData.stationName);
@@ -352,12 +359,11 @@ export const useStore = defineStore('store', {
transports: ['websocket', 'polling'],
rememberUpgrade: true,
reconnection: true,
timeout: 10000,
timeout: 2000,
});
socket.on('connect_error', (err) => {
this.dataStatuses.connection = DataStatus.Error;
this.webSocket = undefined;
});
socket.on('UPDATE', (data: APIData) => {
@@ -368,6 +374,7 @@ export const useStore = defineStore('store', {
socket.emit('FETCH_DATA', {}, (data: APIData) => {
this.apiData = data;
this.dataStatuses.connection = DataStatus.Loaded;
this.setOnlineData();
});