Możliwość dodawania numeru pociągu w linku

This commit is contained in:
2021-09-16 21:33:32 +02:00
parent a559c6799d
commit b6674d411f
5 changed files with 32 additions and 7 deletions
+1 -1
View File
@@ -242,7 +242,7 @@ export default defineComponent({
navigateToTrain(trainNo: number) { navigateToTrain(trainNo: number) {
this.$router.push({ this.$router.push({
name: "TrainsView", name: "TrainsView",
params: { train: trainNo.toString() }, query: { train: trainNo.toString() },
}); });
}, },
}, },
@@ -51,7 +51,7 @@
<router-link <router-link
:to="{ :to="{
name: 'TrainsView', name: 'TrainsView',
params: { query: {
train: scheduledTrain.trainNo.toString(), train: scheduledTrain.trainNo.toString(),
}, },
}" }"
+28 -2
View File
@@ -169,7 +169,7 @@
> >
<TrainSchedule <TrainSchedule
v-if="showedSchedule === train.timetableData?.timetableId" v-if="showedSchedule === train.timetableData?.timetableId"
:followingStops="train.timetableData.followingStops" :followingStops="train.timetableData?.followingStops"
@click="changeScheduleShowState(train.timetableData?.timetableId)" @click="changeScheduleShowState(train.timetableData?.timetableId)"
/> />
</transition> </transition>
@@ -188,8 +188,10 @@ import {
computed, computed,
ComputedRef, ComputedRef,
defineComponent, defineComponent,
reactive,
Ref, Ref,
ref, ref,
watch,
} from "@vue/runtime-core"; } from "@vue/runtime-core";
import { useStore } from "@/store"; import { useStore } from "@/store";
import { GETTERS } from "@/constants/storeConstants"; import { GETTERS } from "@/constants/storeConstants";
@@ -270,6 +272,20 @@ export default defineComponent({
() => store.getters[GETTERS.timetableDataStatus] () => store.getters[GETTERS.timetableDataStatus]
); );
const queryTimetable = computed(
() =>
props.computedTrains.find(
(train) => train.trainNo === Number(props.queryTrain)
)?.timetableData
);
// watch(
// () => queryTimetable.value,
// (val, prevVal) => {
// }
// );
// const observer = new IntersectionObserver((entries) => { // const observer = new IntersectionObserver((entries) => {
// entries.forEach((entry) => { // entries.forEach((entry) => {
// if (entry.isIntersecting) { // if (entry.isIntersecting) {
@@ -283,6 +299,7 @@ export default defineComponent({
return { return {
elList, elList,
queryTimetable,
timetableLoaded: computed( timetableLoaded: computed(
() => timetableDataStatus.value === DataStatus.Loaded () => timetableDataStatus.value === DataStatus.Loaded
), ),
@@ -299,6 +316,14 @@ export default defineComponent({
}; };
}, },
// watch: {
// queryTimetable(timetable: Train["timetableData"]) {
// if (!timetable || !this.queryTrain) return;
// this.focusOnTrain(this.queryTrain);
// },
// },
methods: { methods: {
enter(el: HTMLElement) { enter(el: HTMLElement) {
const maxHeight = getComputedStyle(el).height; const maxHeight = getComputedStyle(el).height;
@@ -323,6 +348,7 @@ export default defineComponent({
el.style.height = "0px"; el.style.height = "0px";
}, 10); }, 10);
}, },
focusOnTrain(trainNoStr: string) { focusOnTrain(trainNoStr: string) {
const timetableId = this.computedTrains.find( const timetableId = this.computedTrains.find(
(train) => train.trainNo == Number(trainNoStr) (train) => train.trainNo == Number(trainNoStr)
@@ -346,7 +372,7 @@ export default defineComponent({
behavior: "smooth", behavior: "smooth",
block: this.showedSchedule == 0 ? "nearest" : "center", block: this.showedSchedule == 0 ? "nearest" : "center",
}); });
}, 175); }, 200);
}, },
onImageError(e: Event) { onImageError(e: Event) {
+1 -2
View File
@@ -12,8 +12,7 @@ const routes: Array<RouteRecordRaw> = [
path: "/trains", path: "/trains",
name: "TrainsView", name: "TrainsView",
component: () => import("@/views/TrainsView.vue"), component: () => import("@/views/TrainsView.vue"),
props: true, props: route => ({ train: route.query.train })
}, },
{ {
path: "/scenery", path: "/scenery",
+1 -1
View File
@@ -257,7 +257,7 @@ export default defineComponent({
this.$router.push({ this.$router.push({
name: "TrainsView", name: "TrainsView",
params: { train: trainNo.toString() }, query: { train: trainNo.toString() },
}); });
}, },