TODO: fix draw logic
[vchess.git] / client / src / components / MoveList.vue
CommitLineData
430a2038
BA
1<template lang="pug">
2div
3 #scoreInfo(v-if="score!='*'")
4 p {{ score }}
5 p {{ message }}
d36ca198 6 table.moves-list
430a2038
BA
7 tbody
8 tr(v-for="moveIdx in evenNumbers")
5157ce0b 9 td {{ firstNum + moveIdx / 2 + 1 }}
430a2038 10 td(:class="{'highlight-lm': cursor == moveIdx}"
96e9585a 11 @click="() => gotoMove(moveIdx)")
430a2038
BA
12 | {{ moves[moveIdx].notation }}
13 td(v-if="moveIdx < moves.length-1"
14 :class="{'highlight-lm': cursor == moveIdx+1}"
96e9585a 15 @click="() => gotoMove(moveIdx+1)")
430a2038
BA
16 | {{ moves[moveIdx+1].notation }}
17 // Else: just add an empty cell
18 td(v-else)
19</template>
20
cf2343ce 21<script>
a3ab5fdb 22// Component for moves list on the right
cf2343ce
BA
23export default {
24 name: 'my-move-list',
5157ce0b 25 props: ["moves","cursor","score","message","firstNum"],
430a2038
BA
26 watch: {
27 cursor: function(newValue) {
d36ca198
BA
28 if (window.innerWidth <= 767)
29 return; //moves list is below: scrolling would hide chessboard
3837d4f7
BA
30 if (newValue < 0)
31 newValue = 0; //avoid rows[-1] --> error
430a2038
BA
32 // $nextTick to wait for table > tr to be rendered
33 this.$nextTick( () => {
34 let rows = document.querySelectorAll('#movesList tr');
35 if (rows.length > 0)
36 {
37 rows[Math.floor(newValue/2)].scrollIntoView({
63ca2b89
BA
38 behavior: "auto",
39 block: "nearest",
430a2038
BA
40 });
41 }
42 });
43 },
44 },
45 computed: {
46 evenNumbers: function() {
47 return [...Array(this.moves.length).keys()].filter(i => i%2==0);
48 },
49 },
50 methods: {
51 gotoMove: function(index) {
52 this.$emit("goto-move", index);
53 },
54 },
55};
56</script>
57
58<style lang="sass" scoped>
59.moves-list
60 min-width: 250px
41c80bb6
BA
61@media screen and (max-width: 767px)
62 .moves-list
63 tr
64 display: flex
65 margin: 0
66 padding: 0
67 td
68 text-align: left
430a2038
BA
69td.highlight-lm
70 background-color: plum
71</style>