mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 13:28:11 +00:00
PWA: tryb offline
This commit is contained in:
+11
-4
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user