Poprawki w działaniu odświeżania danych

This commit is contained in:
2022-01-01 20:19:48 +01:00
parent b3b150d64f
commit a3cba4e7ed
3 changed files with 18 additions and 84 deletions
+11 -11
View File
@@ -34,7 +34,7 @@
</button>
</div>
<span class="timetable-item loading" v-if="dataStatus == 0">
<span class="timetable-item loading" v-if="timetableDataStatus == 0">
{{ $t("app.loading") }}
</span>
@@ -138,6 +138,10 @@ import Station from "@/scripts/interfaces/Station";
import SelectBox from "../Global/SelectBox.vue";
import { computed, defineComponent, ref } from "@vue/runtime-core";
import { useRoute } from "vue-router";
import { useStore } from "@/store";
import { GETTERS } from "@/constants/storeConstants";
import { DataStatus } from "@/scripts/enums/DataStatus";
import { ComputedRef } from "vue";
export default defineComponent({
components: { SelectBox },
@@ -149,9 +153,6 @@ export default defineComponent({
timetableOnly: {
type: Boolean,
},
dataStatus: {
type: Number,
},
},
data: () => ({
@@ -163,22 +164,20 @@ export default defineComponent({
const route = useRoute();
const currentURL = computed(() => `${location.origin}${route.fullPath}`);
const store = useStore();
const timetableDataStatus = computed(() => store.getters[GETTERS.timetableDataStatus]) as ComputedRef<DataStatus>
const selectedCheckpoint = ref("");
const computedScheduledTrains = computed(() => {
if (!props.station) return [];
if (!props.station) return [];
let scheduledTrains =
props.station.generalInfo?.checkpoints.find(
(cp) => cp.checkpointName === selectedCheckpoint.value
)?.scheduledTrains || props.station.onlineInfo?.scheduledTrains || [];
// if (props.station.checkpoints)
// scheduledTrains = props.station.checkpoints.find(
// (cp) => cp.checkpointName === selectedCheckpoint.value
// )?.scheduledTrains;
// else scheduledTrains = props.station.scheduledTrains;
return (
scheduledTrains?.sort((a, b) => {
if (a.stopStatusID > b.stopStatusID) return 1;
@@ -200,6 +199,7 @@ export default defineComponent({
currentURL,
selectedCheckpoint,
computedScheduledTrains,
timetableDataStatus
};
},
+7 -72
View File
@@ -43,32 +43,8 @@ export interface State {
listenerLaunched: boolean;
}
// interface SceneryData {
// id: number;
// name: string;
// url: string;
// project_lines: string;
// project_name: string;
// req_level?: number;
// supporters_only: boolean;
// signal_type: string;
// control_type: string;
// sbl_routes: string;
// twb_routes: string;
// track_oneway_e: number;
// track_oneway_ne: number;
// track_twoway_e: number;
// track_twoway_ne: number;
// checkpoints?: string;
// is_default: boolean;
// is_nonpublic: boolean;
// is_unavailable: boolean;
// }
type StationJSONData = [string, string, string, string, string, string, string, string, string, string, number, number, number, number, string | null, boolean, boolean, boolean];
// const initStationData = (initData: any[][])
export const key: InjectionKey<Store<State>> = Symbol()
export const store = createStore<State>({
@@ -227,6 +203,8 @@ export const store = createStore<State>({
},
async fetchTimetableData({ commit }) {
commit(MUTATIONS.SET_TIMETABLE_DATA_STATUS, DataStatus.Loading);
const reducedList = this.state.trainList.reduce(async (acc: Promise<Timetable[]>, train: Train) => {
const timetable: TimetableAPIData = await (await axios.get(URLs.getTimetableURL(train.trainNo, this.state.region.id))).data.message;
const trainInfo = timetable.trainInfo;
@@ -311,59 +289,13 @@ export const store = createStore<State>({
}, Promise.resolve([]));
commit(MUTATIONS.UPDATE_TIMETABLES, (await reducedList));
commit(MUTATIONS.SET_TIMETABLE_DATA_STATUS, DataStatus.Loaded);
}
},
mutations: {
SET_SCENERY_DATA(state, data: StationJSONData[]) {
// state.sceneryData = [...data];
// state.stationList = data.map(scenery => ({
// stationName: scenery.name,
// stationURL: scenery.url,
// stationLines: scenery.project_lines,
// stationProject: scenery.project_name,
// reqLevel: scenery.req_level === undefined ? -1 : scenery.req_level,
// supportersOnly: scenery.supporters_only,
// signalType: scenery.signal_type,
// controlType: scenery.control_type,
// SBL: scenery.sbl_routes,
// TWB: scenery.twb_routes,
// routes: {
// oneWay: {
// catenary: scenery.track_oneway_e,
// noCatenary: scenery.track_oneway_ne
// },
// twoWay: {
// catenary: scenery.track_twoway_e,
// noCatenary: scenery.track_twoway_ne
// }
// },
// checkpoints: scenery.checkpoints ? scenery.checkpoints.split(";").map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : [],
// default: scenery.is_default,
// nonPublic: scenery.is_nonpublic,
// unavailable: scenery.is_unavailable,
// stationHash: "",
// maxUsers: 0,
// currentUsers: 0,
// dispatcherName: "",
// dispatcherRate: 0,
// dispatcherExp: -1,
// dispatcherId: 0,
// dispatcherIsSupporter: false,
// online: false,
// statusTimestamp: -3,
// statusID: "free",
// statusTimeString: "",
// stationTrains: [],
// scheduledTrains: [],
// spawns: []
// }));
state.stationList = data.map(station => ({
name: station[0],
@@ -425,7 +357,10 @@ export const store = createStore<State>({
acc.push({
name: station.name,
generalInfo: station.generalInfo,
onlineInfo: onlineStationData,
onlineInfo: {
...onlineStationData,
scheduledTrains: station.onlineInfo?.scheduledTrains || []
},
});
else if (listedStationData)
acc.push({
-1
View File
@@ -17,7 +17,6 @@
<SceneryTimetable
:station="stationInfo"
:timetableOnly="timetableOnly"
:dataStatus="data.timetableDataStatus"
/>
</div>
</div>