chore(wiki): preserving scroll state

This commit is contained in:
2024-04-16 20:06:23 +02:00
parent 897d6d0c36
commit f9cd9a2a33
+13 -2
View File
@@ -50,7 +50,7 @@
:data-preview="vehicle.type === store.chosenVehicle?.type" :data-preview="vehicle.type === store.chosenVehicle?.type"
@click="previewVehicle(vehicle)" @click="previewVehicle(vehicle)"
@dblclick="addVehicle(vehicle)" @dblclick="addVehicle(vehicle)"
@keydown.enter="previewVehicle(vehicle)" @keydown.enter="onVehicleSelect(vehicle)"
tabindex="0" tabindex="0"
> >
<img loading="lazy" width="120" :src="getThumbnailURL(vehicle.type, 'small')" /> <img loading="lazy" width="120" :src="getThumbnailURL(vehicle.type, 'small')" />
@@ -117,9 +117,19 @@ export default defineComponent({
sorterDirection: 'asc' as SorterDirection, sorterDirection: 'asc' as SorterDirection,
filterType: 'vehicles-all' as FilterType, filterType: 'vehicles-all' as FilterType,
lastScrollTop: 0,
}; };
}, },
deactivated() {
this.lastScrollTop = (this.$refs['vehicles'] as HTMLUListElement)?.scrollTop || 0;
},
activated() {
(this.$refs['vehicles'] as HTMLUListElement)?.scrollTo({ top: this.lastScrollTop });
},
watch: { watch: {
computedVehicles() { computedVehicles() {
const vehiclesRef = this.$refs['vehicles'] as HTMLElement; const vehiclesRef = this.$refs['vehicles'] as HTMLElement;
@@ -133,7 +143,8 @@ export default defineComponent({
methods: { methods: {
isTractionUnit, isTractionUnit,
onItemSelect(vehicle: IVehicle) { onVehicleSelect(vehicle: IVehicle) {
if (this.store.chosenVehicle?.type === vehicle.type) this.addVehicle(vehicle);
this.previewVehicle(vehicle); this.previewVehicle(vehicle);
}, },