Skip to content

Commit

Permalink
Update GameSelection.vue
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Oct 29, 2024
1 parent 2edb7a7 commit 303456f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions frontend/src/views/GameSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,28 @@ const scrollIndex = ref(0)
const scrollToGame = () => {
const i = scrollIndex.value
if (i < 0 || i >= gameElements.value.length) return // Ensure no OOB
// This should never happen. If it does, shame the guy who gave scrollIndex a bad value. (Probably me)
if (i < 0 || i >= gameElements.value.length) {
console.warn(`Prevented OOB access of 'gameElements'. Scroll index: ${i}`)
return
}
const game = gameElements.value[i]
if (!game) return
(game as Element).scrollIntoView({ block: 'start' })
}
// NOTE: Might want to make this a ref in future so it can be user defined.
const SCROLL_STEP = 1
const handleScroll = (e: WheelEvent) => {
if (e.deltaY > 0) {
// Scrolling down
if (scrollIndex.value < gameElements.value.length - 1) {
scrollIndex.value++
}
} else if (scrollIndex.value > 0) {
scrollIndex.value--
if (e.deltaY > 0) {
const lastGameIndex = gameElements.value.length - 1
scrollIndex.value = Math.min(scrollIndex.value + SCROLL_STEP, lastGameIndex)
} else {
scrollIndex.value = Math.max(scrollIndex.value - SCROLL_STEP, 0)
}
// Scroll to the next div element in game list.
Expand Down

0 comments on commit 303456f

Please sign in to comment.