6 th {{ st.tr["Variant"] }}
7 th {{ st.tr[showBoth ? "Players" : "Versus"] }}
8 th(v-if="showCadence") {{ st.tr["Cadence"] }}
9 th {{ st.tr["Result"] }}
11 tr(v-for="g in sortedGames" @click="$emit('show-game',g)"
12 :class="{'my-turn': g.myTurn}")
15 td(v-if="showCadence") {{ g.cadence }}
16 td(:class="{finished: g.score!='*'}" @click="deleteGame(g,$event)")
21 import { store } from "@/store";
22 import { GameStorage } from "@/utils/gameStorage";
25 props: ["games", "showBoth"],
33 // timeout to avoid calling too many time the adjust method
34 let timeoutLaunched = false;
35 window.addEventListener("resize", () => {
36 if (!timeoutLaunched) {
37 timeoutLaunched = true;
39 this.showCadence = window.innerWidth >= 425; //TODO: arbitrary
40 timeoutLaunched = false;
46 sortedGames: function() {
47 // Show in order: games where it's my turn, my running games, my games, other games
48 let minCreated = Number.MAX_SAFE_INTEGER;
50 let augmentedGames = this.games.map(g => {
54 p => p.uid == this.st.user.id || p.sid == this.st.user.sid
61 g.players[0].uid == this.st.user.id ||
62 g.players[0].sid == this.st.user.sid
65 // I play in this game, so g.fen will be defined
66 if (g.fen.match(" " + myColor + " ")) priority++;
69 if (g.created < minCreated) minCreated = g.created;
70 if (g.created > maxCreated) maxCreated = g.created;
71 return Object.assign({}, g, {
76 const deltaCreated = maxCreated - minCreated;
77 return augmentedGames.sort((g1, g2) => {
79 g2.priority - g1.priority + (g2.created - g1.created) / deltaCreated
85 player_s: function(g) {
88 (g.players[0].name || "@nonymous") +
90 (g.players[1].name || "@nonymous")
93 this.st.user.sid == g.players[0].sid ||
94 this.st.user.id == g.players[0].uid
96 return g.players[1].name || "@nonymous";
97 return g.players[0].name || "@nonymous";
99 deleteGame: function(game, e) {
100 if (game.score != "*") {
101 if (confirm(this.st.tr["Remove game?"])) GameStorage.remove(game.id);
109 <style lang="sass" scoped>
110 // TODO: understand why the style applied to <tr> element doesn't work
112 background-color: #fcd785
114 background-color: #f5b7b1