mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-04 22: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 = {
|
export const URLs = {
|
||||||
|
sceneryData: "https://spythere.github.io/api/stationData.json",
|
||||||
stations: "https://api.td2.info.pl:9640/?method=getStationsOnline",
|
stations: "https://api.td2.info.pl:9640/?method=getStationsOnline",
|
||||||
trains: "https://api.td2.info.pl:9640/?method=getTrainsOnline",
|
trains: "https://api.td2.info.pl:9640/?method=getTrainsOnline",
|
||||||
dispatchers: "https://api.td2.info.pl:9640/?method=readFromSWDR&value=getDispatcherStatusList%3B1",
|
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 axios from "axios";
|
||||||
|
|
||||||
import JSONStationData from "@/data/stationData.json";
|
// import JSONStationData from "@/data/stationData.json";
|
||||||
|
|
||||||
import Station from "@/scripts/interfaces/Station";
|
import Station from "@/scripts/interfaces/Station";
|
||||||
import Train from "@/scripts/interfaces/Train";
|
import Train from "@/scripts/interfaces/Train";
|
||||||
@@ -28,6 +28,8 @@ export interface State {
|
|||||||
stationList: Station[],
|
stationList: Station[],
|
||||||
trainList: Train[],
|
trainList: Train[],
|
||||||
|
|
||||||
|
sceneryData: any[][],
|
||||||
|
|
||||||
region: { id: string; value: string };
|
region: { id: string; value: string };
|
||||||
trainCount: number;
|
trainCount: number;
|
||||||
stationCount: number;
|
stationCount: number;
|
||||||
@@ -46,6 +48,8 @@ export const store = createStore<State>({
|
|||||||
stationList: [],
|
stationList: [],
|
||||||
trainList: [],
|
trainList: [],
|
||||||
|
|
||||||
|
sceneryData: [],
|
||||||
|
|
||||||
region: { id: "eu", value: "PL1" },
|
region: { id: "eu", value: "PL1" },
|
||||||
|
|
||||||
trainCount: 0,
|
trainCount: 0,
|
||||||
@@ -81,7 +85,9 @@ export const store = createStore<State>({
|
|||||||
async synchronizeData({ commit, dispatch, state }) {
|
async synchronizeData({ commit, dispatch, state }) {
|
||||||
if (state.listenerLaunched) return;
|
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);
|
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
|
||||||
|
|
||||||
dispatch(ACTIONS.fetchOnlineData);
|
dispatch(ACTIONS.fetchOnlineData);
|
||||||
@@ -92,12 +98,15 @@ export const store = createStore<State>({
|
|||||||
async fetchOnlineData({ commit, dispatch }) {
|
async fetchOnlineData({ commit, dispatch }) {
|
||||||
commit(MUTATIONS.SET_DATA_CONNECTION_STATUS, DataStatus.Loading);
|
commit(MUTATIONS.SET_DATA_CONNECTION_STATUS, DataStatus.Loading);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Promise.all([axios.get(URLs.stations), axios.get(URLs.trains), axios.get(URLs.dispatchers)])
|
Promise.all([axios.get(URLs.stations), axios.get(URLs.trains), axios.get(URLs.dispatchers)])
|
||||||
.then(async response => {
|
.then(async response => {
|
||||||
const onlineStationsData: StationAPIData[] = response[0].data.message;
|
const onlineStationsData: StationAPIData[] = response[0].data.message;
|
||||||
const onlineTrainsData: TrainAPIData[] = await response[1].data.message;
|
const onlineTrainsData: TrainAPIData[] = await response[1].data.message;
|
||||||
const onlineDispatchersData: string[][] = await response[2].data.message;
|
const onlineDispatchersData: string[][] = await response[2].data.message;
|
||||||
|
|
||||||
|
|
||||||
const updatedStationList = onlineStationsData.reduce((acc, station) => {
|
const updatedStationList = onlineStationsData.reduce((acc, station) => {
|
||||||
if (station.region !== this.state.region.id || !station.isOnline) return acc;
|
if (station.region !== this.state.region.id || !station.isOnline) return acc;
|
||||||
|
|
||||||
@@ -242,8 +251,10 @@ export const store = createStore<State>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_SCENERY_DATA(state) {
|
SET_SCENERY_DATA(state, data: any[][]) {
|
||||||
state.stationList = JSONStationData.map(station => ({
|
state.sceneryData = [...data];
|
||||||
|
|
||||||
|
state.stationList = data.map(station => ({
|
||||||
stationName: station[0] as string,
|
stationName: station[0] as string,
|
||||||
stationURL: station[1] as string,
|
stationURL: station[1] as string,
|
||||||
stationLines: station[2] as string,
|
stationLines: station[2] as string,
|
||||||
@@ -286,6 +297,8 @@ export const store = createStore<State>({
|
|||||||
scheduledTrains: [],
|
scheduledTrains: [],
|
||||||
spawns: []
|
spawns: []
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
SET_SCENERY_DATA_STATUS(state, status: DataStatus) {
|
SET_SCENERY_DATA_STATUS(state, status: DataStatus) {
|
||||||
@@ -305,9 +318,10 @@ export const store = createStore<State>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
UPDATE_STATIONS(state, updatedStationList: any[]) {
|
UPDATE_STATIONS(state, updatedStationList: any[]) {
|
||||||
|
|
||||||
state.stationList = state.stationList.reduce((acc: Station[], station) => {
|
state.stationList = state.stationList.reduce((acc: Station[], station) => {
|
||||||
const onlineStationData = updatedStationList.find(updatedStation => updatedStation.stationName === station.stationName);
|
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)
|
if (onlineStationData)
|
||||||
acc.push({
|
acc.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user