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"
@click="previewVehicle(vehicle)"
@dblclick="addVehicle(vehicle)"
@keydown.enter="previewVehicle(vehicle)"
@keydown.enter="onVehicleSelect(vehicle)"
tabindex="0"
>
<img loading="lazy" width="120" :src="getThumbnailURL(vehicle.type, 'small')" />
@@ -117,9 +117,19 @@ export default defineComponent({
sorterDirection: 'asc' as SorterDirection,
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: {
computedVehicles() {
const vehiclesRef = this.$refs['vehicles'] as HTMLElement;
@@ -133,7 +143,8 @@ export default defineComponent({
methods: {
isTractionUnit,
onItemSelect(vehicle: IVehicle) {
onVehicleSelect(vehicle: IVehicle) {
if (this.store.chosenVehicle?.type === vehicle.type) this.addVehicle(vehicle);
this.previewVehicle(vehicle);
},