mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-02 21:08:12 +00:00
Plik z danymi przerzucono do API
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,4 +1,5 @@
|
||||
export const URLs = {
|
||||
sceneryData: "https://spythere.github.io/api/stationData.json",
|
||||
stations: "https://api.td2.info.pl:9640/?method=getStationsOnline",
|
||||
trains: "https://api.td2.info.pl:9640/?method=getTrainsOnline",
|
||||
dispatchers: "https://api.td2.info.pl:9640/?method=readFromSWDR&value=getDispatcherStatusList%3B1",
|
||||
|
||||
+19
-5
@@ -5,7 +5,7 @@ import { createStore, useStore as baseUseStore, Store } from 'vuex'
|
||||
|
||||
import axios from "axios";
|
||||
|
||||
import JSONStationData from "@/data/stationData.json";
|
||||
// import JSONStationData from "@/data/stationData.json";
|
||||
|
||||
import Station from "@/scripts/interfaces/Station";
|
||||
import Train from "@/scripts/interfaces/Train";
|
||||
@@ -28,6 +28,8 @@ export interface State {
|
||||
stationList: Station[],
|
||||
trainList: Train[],
|
||||
|
||||
sceneryData: any[][],
|
||||
|
||||
region: { id: string; value: string };
|
||||
trainCount: number;
|
||||
stationCount: number;
|
||||
@@ -46,6 +48,8 @@ export const store = createStore<State>({
|
||||
stationList: [],
|
||||
trainList: [],
|
||||
|
||||
sceneryData: [],
|
||||
|
||||
region: { id: "eu", value: "PL1" },
|
||||
|
||||
trainCount: 0,
|
||||
@@ -81,7 +85,9 @@ export const store = createStore<State>({
|
||||
async synchronizeData({ commit, dispatch, state }) {
|
||||
if (state.listenerLaunched) return;
|
||||
|
||||
commit(MUTATIONS.SET_SCENERY_DATA);
|
||||
const sceneryData = await (await axios.get(URLs.sceneryData + "?time=" + Date.now())).data;
|
||||
|
||||
commit(MUTATIONS.SET_SCENERY_DATA, sceneryData);
|
||||
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
|
||||
|
||||
dispatch(ACTIONS.fetchOnlineData);
|
||||
@@ -92,12 +98,15 @@ export const store = createStore<State>({
|
||||
async fetchOnlineData({ commit, dispatch }) {
|
||||
commit(MUTATIONS.SET_DATA_CONNECTION_STATUS, DataStatus.Loading);
|
||||
|
||||
|
||||
|
||||
Promise.all([axios.get(URLs.stations), axios.get(URLs.trains), axios.get(URLs.dispatchers)])
|
||||
.then(async response => {
|
||||
const onlineStationsData: StationAPIData[] = response[0].data.message;
|
||||
const onlineTrainsData: TrainAPIData[] = await response[1].data.message;
|
||||
const onlineDispatchersData: string[][] = await response[2].data.message;
|
||||
|
||||
|
||||
const updatedStationList = onlineStationsData.reduce((acc, station) => {
|
||||
if (station.region !== this.state.region.id || !station.isOnline) return acc;
|
||||
|
||||
@@ -242,8 +251,10 @@ export const store = createStore<State>({
|
||||
},
|
||||
|
||||
mutations: {
|
||||
SET_SCENERY_DATA(state) {
|
||||
state.stationList = JSONStationData.map(station => ({
|
||||
SET_SCENERY_DATA(state, data: any[][]) {
|
||||
state.sceneryData = [...data];
|
||||
|
||||
state.stationList = data.map(station => ({
|
||||
stationName: station[0] as string,
|
||||
stationURL: station[1] as string,
|
||||
stationLines: station[2] as string,
|
||||
@@ -286,6 +297,8 @@ export const store = createStore<State>({
|
||||
scheduledTrains: [],
|
||||
spawns: []
|
||||
}));
|
||||
|
||||
|
||||
},
|
||||
|
||||
SET_SCENERY_DATA_STATUS(state, status: DataStatus) {
|
||||
@@ -305,9 +318,10 @@ export const store = createStore<State>({
|
||||
},
|
||||
|
||||
UPDATE_STATIONS(state, updatedStationList: any[]) {
|
||||
|
||||
state.stationList = state.stationList.reduce((acc: Station[], station) => {
|
||||
const onlineStationData = updatedStationList.find(updatedStation => updatedStation.stationName === station.stationName);
|
||||
const listedStationData = JSONStationData.find(data => data[0] === station.stationName);
|
||||
const listedStationData = state.sceneryData.find(data => data[0] === station.stationName);
|
||||
|
||||
if (onlineStationData)
|
||||
acc.push({
|
||||
|
||||
Reference in New Issue
Block a user