Skip to content

Commit

Permalink
Add scrolling to stratagem select & stratagem list when selecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tackx committed Mar 29, 2024
1 parent 38f82bb commit 9bcfe21
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/views/System/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
<RSelection
:selected-stratagems="data.playerList[i].stratagemCodeList"
:color="player.color"
@stratagem-selected="stratagemSelectionHandler"
ref="modalRef"></RSelection>
@stratagem-selected="handleStratagemSelection"
ref="modalRef"
:id="`stratagem-select-${i}`"></RSelection>
<img
:class="`mt-2 h-[50px] w-[50px] rounded-md border-4 border-solid border-gray-900 hover:border-4 hover:border-solid ${playerBordersHover[player.color]} ${activeStratagemSelect[i][j] ? `border-4 border-solid ${playerBorders[player.color]}` : ''}`"
v-for="(stratagem, j) in player.stratagemCodeList"
Expand All @@ -87,7 +88,7 @@
</template>

<script setup lang="ts">
import { inject, reactive, ref, watch } from 'vue'
import { inject, nextTick, reactive, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import type { ToastPluginApi } from 'vue-toast-notification'
Expand Down Expand Up @@ -166,6 +167,14 @@
}
})
nextTick(() => {
document.querySelector(`#stratagem-select-${playerIndex}`)?.scrollIntoView({ behavior: 'smooth' })
})
// setTimeout(() => {
// document.querySelector(`#stratagem-select-${playerIndex}`)?.scrollIntoView({ behavior: 'smooth' }), 0
// })
if (modalRef.value[playerIndex].playerIndex === playerIndex && modalRef.value[playerIndex].position === position) {
modalRef.value[playerIndex].displayOff()
modalRef.value[playerIndex].playerIndex = null
Expand All @@ -176,10 +185,11 @@
modalRef.value[playerIndex].displayOn()
}
}
const stratagemSelectionHandler = (playerIndex: number, position: number, stratagemCode: keyof typeof stratagems) => {
const handleStratagemSelection = (playerIndex: number, position: number, stratagemCode: keyof typeof stratagems) => {
data.playerList[playerIndex].stratagemCodeList[position] = stratagemCode
activeStratagemSelect.value[playerIndex][position] = false
modalRef.value[playerIndex].displayOff()
document.querySelector(`#secondary-${playerIndex}`)?.scrollIntoView({ behavior: 'smooth' })
modalRef.value[playerIndex].playerIndex = null
modalRef.value[playerIndex].position = null
}
Expand Down

0 comments on commit 9bcfe21

Please sign in to comment.