Will remove Welcome div, finally
[vchess.git] / client / src / components / GameList.vue
1 <template lang="pug">
2 div
3 table
4 thead
5 tr
6 th {{ st.tr["Variant"] }}
7 th {{ st.tr["White"] }}
8 th {{ st.tr["Black"] }}
9 th {{ st.tr["Cadence"] }}
10 th {{ st.tr["Result"] }}
11 tbody
12 tr(v-for="g in sortedGames" @click="$emit('show-game',g)"
13 :class="{'my-turn': g.myTurn}")
14 td(data-label="Variant") {{ g.vname }}
15 td(data-label="White") {{ g.players[0].name || "@nonymous" }}
16 td(data-label="Black") {{ g.players[1].name || "@nonymous" }}
17 td(data-label="Time control") {{ g.cadence }}
18 td(data-label="Result" :class="{finished: g.score!='*'}" @click="deleteGame(g,$event)")
19 | {{ g.score }}
20 </template>
21
22 <script>
23 import { store } from "@/store";
24 import { GameStorage } from "@/utils/gameStorage";
25 export default {
26 name: "my-game-list",
27 props: ["games"],
28 data: function() {
29 return {
30 st: store.state,
31 };
32 },
33 computed: {
34 // TODO: also sort by g.created
35 sortedGames: function() {
36 // Show in order: games where it's my turn, my running games, my games, other games
37 let augmentedGames = this.games.map(g => {
38 let priority = 0;
39 if (g.players.some(p => p.uid == this.st.user.id || p.sid == this.st.user.sid))
40 {
41 priority++;
42 if (g.score == "*")
43 {
44 priority++;
45 const myColor = g.players[0].uid == this.st.user.id
46 || g.players[0].sid == this.st.user.sid
47 ? "w"
48 : "b";
49 // I play in this game, so g.fen will be defined
50 if (!!g.fen.match(" " + myColor + " "))
51 priority++;
52 }
53 }
54 return Object.assign({}, g, {priority: priority, myTurn: priority==3});
55 });
56 return augmentedGames.sort((g1,g2) => { return g2.priority - g1.priority; });
57 },
58 },
59 methods: {
60 deleteGame: function(game, e) {
61 if (game.score != "*")
62 {
63 if (confirm(this.st.tr["Remove game?"]))
64 GameStorage.remove(game.id);
65 e.stopPropagation();
66 }
67 },
68 },
69 };
70 </script>
71
72 <style lang="sass" scoped>
73 // TODO: understand why the style applied to <tr> element doesn't work
74 tr.my-turn > td
75 background-color: #fcd785
76 tr td.finished
77 background-color: #f5b7b1
78 </style>