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"] }}
12 v-for="g in sortedGames"
13 @click="$emit('show-game',g)"
14 :class="{'my-turn': g.myTurn}"
18 td(v-if="showCadence") {{ g.cadence }}
20 :class="scoreClass(g)"
21 @click="deleteGame(g,$event)"
27 import { store } from "@/store";
28 import { GameStorage } from "@/utils/gameStorage";
31 props: ["games", "showBoth"],
39 // timeout to avoid calling too many time the adjust method
40 let timeoutLaunched = false;
41 window.addEventListener("resize", () => {
42 if (!timeoutLaunched) {
43 timeoutLaunched = true;
45 this.showCadence = window.innerWidth >= 425; //TODO: arbitrary
46 timeoutLaunched = false;
52 sortedGames: function() {
53 // Show in order: games where it's my turn, my running games, my games, other games
54 let minCreated = Number.MAX_SAFE_INTEGER;
56 let augmentedGames = this.games.map(g => {
58 let myColor = undefined;
61 p => p.uid == this.st.user.id || p.sid == this.st.user.sid
66 g.players[0].uid == this.st.user.id ||
67 g.players[0].sid == this.st.user.sid
72 // I play in this game, so g.fen will be defined
73 // NOTE: this is a fragile way to detect turn,
74 // but since V isn't defined let's do that for now. (TODO:)
75 //if (V.ParseFen(g.fen).turn == myColor)
76 if (g.fen.match(" " + myColor + " ")) priority++;
79 if (g.created < minCreated) minCreated = g.created;
80 if (g.created > maxCreated) maxCreated = g.created;
81 return Object.assign({}, g, {
83 myTurn: priority == 3,
87 const deltaCreated = maxCreated - minCreated;
88 return augmentedGames.sort((g1, g2) => {
90 g2.priority - g1.priority + (g2.created - g1.created) / deltaCreated
96 player_s: function(g) {
99 (g.players[0].name || "@nonymous") +
101 (g.players[1].name || "@nonymous")
104 this.st.user.sid == g.players[0].sid ||
105 this.st.user.id == g.players[0].uid
107 return g.players[1].name || "@nonymous";
108 return g.players[0].name || "@nonymous";
110 scoreClass: function(g) {
111 if (g.score == "*" || !g.myColor) return {};
112 // Ok it's my finished game: determine if I won, drew or lost.
116 res[g.myColor == "w" ? "won" : "lost"] = true;
119 res[g.myColor == "b" ? "won" : "lost"] = true;
124 // default case: "?" for unknown finished
126 res["unknown"] = true;
130 deleteGame: function(game, e) {
131 if (game.score != "*") {
132 if (confirm(this.st.tr["Remove game?"])) GameStorage.remove(game.id);
140 <style lang="sass" scoped>
141 // NOTE: the style applied to <tr> element doesn't work
143 background-color: #fcd785
147 background-color: #f5b7b1
149 background-color: lightgreen
151 background-color: lightblue
153 background-color: lightgrey