Skip to content

Commit f1bd0a2

Browse files
committed
smooth scroll expanded sidebar items and reset view
1 parent ca4f40e commit f1bd0a2

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

via-ui/src/components/Departure.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script setup lang="ts">
2-
import { ref, watch, onMounted, onUnmounted } from 'vue'
2+
import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue'
33
import type { Departure } from '@/api/gtfs/types.ts'
44
import { useGameManager } from '@/api/game/manager.ts'
55
import { getIconFilename } from '@/api/game/icons.ts'
66
7-
const { chooseTrain, showTripPreview, clearTripPreview } = useGameManager()
7+
const { chooseTrain, showTripPreview } = useGameManager()
88
99
const props = defineProps<{
1010
departure: Departure
@@ -22,7 +22,7 @@ function previewRoute() {
2222
}
2323
2424
function clearPreview() {
25-
clearTripPreview()
25+
// Clear preview logic
2626
}
2727
2828
function handleClickOutside(event: MouseEvent) {
@@ -31,9 +31,18 @@ function handleClickOutside(event: MouseEvent) {
3131
}
3232
}
3333
34-
watch(isOpen, (newVal) => {
34+
watch(isOpen, async (newVal) => {
3535
if (newVal) {
3636
previewRoute()
37+
38+
// Wait for DOM to update, then smoothly scroll the item into view
39+
await nextTick()
40+
setTimeout(() => {
41+
collapseRef.value?.scrollIntoView({
42+
behavior: 'smooth',
43+
block: 'nearest',
44+
})
45+
}, 150) // Matches DaisyUI transition timing
3746
} else {
3847
clearPreview()
3948
}

via-ui/src/components/SideBar.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
<script setup lang="ts">
22
import { useGameManager } from '@/api/game/manager.ts'
33
import Departure from '@/components/Departure.vue'
4-
import { computed } from 'vue'
4+
import { computed, ref, watch, nextTick } from 'vue'
55
import Stop from '@/components/Stop.vue'
66
import { getIconFilename } from '@/api/game/icons.ts'
77
88
const { gameState } = useGameManager()
99
10+
const scrollContainer = ref<HTMLElement | null>(null)
11+
1012
const 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>

via-ui/src/components/Stop.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
```vue
12
<script setup lang="ts">
2-
import { ref, watch, onMounted, onUnmounted } from 'vue'
3+
import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue'
34
import type { TripStop } from '@/api/gtfs/types.ts'
45
import { useGameManager } from '@/api/game/manager.ts'
56
@@ -30,9 +31,17 @@ function handleClickOutside(event: MouseEvent) {
3031
}
3132
}
3233
33-
watch(isOpen, (newVal) => {
34+
watch(isOpen, async (newVal) => {
3435
if (newVal) {
3536
showPreview()
37+
38+
await nextTick()
39+
setTimeout(() => {
40+
collapseRef.value?.scrollIntoView({
41+
behavior: 'smooth',
42+
block: 'nearest',
43+
})
44+
}, 150)
3645
} else {
3746
clearPreview()
3847
}
@@ -64,3 +73,5 @@ onUnmounted(() => {
6473
</template>
6574

6675
<style scoped></style>
76+
77+
```

0 commit comments

Comments
 (0)