11<script setup lang="ts">
22import { useGameManager } from ' @/api/game/manager.ts'
33import Departure from ' @/components/Departure.vue'
4- import { computed } from ' vue'
4+ import { computed , ref , watch , nextTick } from ' vue'
55import Stop from ' @/components/Stop.vue'
66import { getIconFilename } from ' @/api/game/icons.ts'
77
88const { gameState } = useGameManager ()
99
10+ const scrollContainer = ref <HTMLElement | null >(null )
11+
1012const departureChosen = computed (() => {
1113 return !! gameState .value ?.chosenTrain
1214})
15+
16+ watch (departureChosen , async () => {
17+ await nextTick ()
18+ if (scrollContainer .value ) {
19+ scrollContainer .value .scrollTop = 0
20+ }
21+ })
1322 </script >
1423
1524<template >
@@ -25,9 +34,7 @@ const departureChosen = computed(() => {
2534 class =" flex flex-col items-center justify-center py-4 w-full opacity-50"
2635 >
2736 <span class =" loading loading-spinner loading-xl" ></span >
28- <span class =" text-xs mt-2 font-semibold tracking-wide uppercase"
29- >Loading game...</span
30- >
37+ <span class =" text-xs mt-2 font-semibold tracking-wide uppercase" >Loading game...</span >
3138 </div >
3239
3340 <h2 v-else class =" text-2xl font-bold" >
@@ -56,7 +63,7 @@ const departureChosen = computed(() => {
5663 </div >
5764 </div >
5865
59- <div class =" flex-1 overflow-y-auto p-1 pr-6 pt-2" >
66+ <div ref = " scrollContainer " class =" flex-1 overflow-y-auto p-1 pr-6 pt-2" >
6067 <div v-if =" !departureChosen" class =" flex flex-col gap-1 w-full min-w-0" >
6168 <Departure v-for =" d in gameState .departures " :key =" d .trip_id " :departure =" d " />
6269 </div >
0 commit comments