mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 13:28:11 +00:00
Poprawki w działaniu odświeżania danych
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="timetable-item loading" v-if="dataStatus == 0">
|
<span class="timetable-item loading" v-if="timetableDataStatus == 0">
|
||||||
{{ $t("app.loading") }}
|
{{ $t("app.loading") }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -138,6 +138,10 @@ import Station from "@/scripts/interfaces/Station";
|
|||||||
import SelectBox from "../Global/SelectBox.vue";
|
import SelectBox from "../Global/SelectBox.vue";
|
||||||
import { computed, defineComponent, ref } from "@vue/runtime-core";
|
import { computed, defineComponent, ref } from "@vue/runtime-core";
|
||||||
import { useRoute } from "vue-router";
|
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({
|
export default defineComponent({
|
||||||
components: { SelectBox },
|
components: { SelectBox },
|
||||||
@@ -149,9 +153,6 @@ export default defineComponent({
|
|||||||
timetableOnly: {
|
timetableOnly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
dataStatus: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
data: () => ({
|
data: () => ({
|
||||||
@@ -163,22 +164,20 @@ export default defineComponent({
|
|||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const currentURL = computed(() => `${location.origin}${route.fullPath}`);
|
const currentURL = computed(() => `${location.origin}${route.fullPath}`);
|
||||||
|
|
||||||
|
const store = useStore();
|
||||||
|
|
||||||
|
const timetableDataStatus = computed(() => store.getters[GETTERS.timetableDataStatus]) as ComputedRef<DataStatus>
|
||||||
|
|
||||||
const selectedCheckpoint = ref("");
|
const selectedCheckpoint = ref("");
|
||||||
|
|
||||||
const computedScheduledTrains = computed(() => {
|
const computedScheduledTrains = computed(() => {
|
||||||
if (!props.station) return [];
|
if (!props.station) return [];
|
||||||
|
|
||||||
let scheduledTrains =
|
let scheduledTrains =
|
||||||
props.station.generalInfo?.checkpoints.find(
|
props.station.generalInfo?.checkpoints.find(
|
||||||
(cp) => cp.checkpointName === selectedCheckpoint.value
|
(cp) => cp.checkpointName === selectedCheckpoint.value
|
||||||
)?.scheduledTrains || props.station.onlineInfo?.scheduledTrains || [];
|
)?.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 (
|
return (
|
||||||
scheduledTrains?.sort((a, b) => {
|
scheduledTrains?.sort((a, b) => {
|
||||||
if (a.stopStatusID > b.stopStatusID) return 1;
|
if (a.stopStatusID > b.stopStatusID) return 1;
|
||||||
@@ -200,6 +199,7 @@ export default defineComponent({
|
|||||||
currentURL,
|
currentURL,
|
||||||
selectedCheckpoint,
|
selectedCheckpoint,
|
||||||
computedScheduledTrains,
|
computedScheduledTrains,
|
||||||
|
timetableDataStatus
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+7
-72
@@ -43,32 +43,8 @@ export interface State {
|
|||||||
listenerLaunched: boolean;
|
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];
|
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 key: InjectionKey<Store<State>> = Symbol()
|
||||||
|
|
||||||
export const store = createStore<State>({
|
export const store = createStore<State>({
|
||||||
@@ -227,6 +203,8 @@ export const store = createStore<State>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async fetchTimetableData({ commit }) {
|
async fetchTimetableData({ commit }) {
|
||||||
|
commit(MUTATIONS.SET_TIMETABLE_DATA_STATUS, DataStatus.Loading);
|
||||||
|
|
||||||
const reducedList = this.state.trainList.reduce(async (acc: Promise<Timetable[]>, train: Train) => {
|
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 timetable: TimetableAPIData = await (await axios.get(URLs.getTimetableURL(train.trainNo, this.state.region.id))).data.message;
|
||||||
const trainInfo = timetable.trainInfo;
|
const trainInfo = timetable.trainInfo;
|
||||||
@@ -311,59 +289,13 @@ export const store = createStore<State>({
|
|||||||
}, Promise.resolve([]));
|
}, Promise.resolve([]));
|
||||||
|
|
||||||
commit(MUTATIONS.UPDATE_TIMETABLES, (await reducedList));
|
commit(MUTATIONS.UPDATE_TIMETABLES, (await reducedList));
|
||||||
|
commit(MUTATIONS.SET_TIMETABLE_DATA_STATUS, DataStatus.Loaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_SCENERY_DATA(state, data: StationJSONData[]) {
|
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 => ({
|
state.stationList = data.map(station => ({
|
||||||
name: station[0],
|
name: station[0],
|
||||||
|
|
||||||
@@ -425,7 +357,10 @@ export const store = createStore<State>({
|
|||||||
acc.push({
|
acc.push({
|
||||||
name: station.name,
|
name: station.name,
|
||||||
generalInfo: station.generalInfo,
|
generalInfo: station.generalInfo,
|
||||||
onlineInfo: onlineStationData,
|
onlineInfo: {
|
||||||
|
...onlineStationData,
|
||||||
|
scheduledTrains: station.onlineInfo?.scheduledTrains || []
|
||||||
|
},
|
||||||
});
|
});
|
||||||
else if (listedStationData)
|
else if (listedStationData)
|
||||||
acc.push({
|
acc.push({
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
<SceneryTimetable
|
<SceneryTimetable
|
||||||
:station="stationInfo"
|
:station="stationInfo"
|
||||||
:timetableOnly="timetableOnly"
|
:timetableOnly="timetableOnly"
|
||||||
:dataStatus="data.timetableDataStatus"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user