4 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
6 button.tabbtn#liveGames(@click="setDisplay('live',$event)")
7 | {{ st.tr["Live games"] }}
8 button.tabbtn#corrGames(@click="setDisplay('corr',$event)")
9 | {{ st.tr["Correspondance games"] }}
11 v-show="display=='live'"
16 v-show="display=='corr'"
23 import { store } from "@/store";
24 import { GameStorage } from "@/utils/gameStorage";
25 import { ajax } from "@/utils/ajax";
26 import params from "@/parameters";
27 import { getRandString } from "@/utils/alea";
28 import GameList from "@/components/GameList.vue";
45 GameStorage.getAll(true, localGames => {
46 localGames.forEach(g => (g.type = this.classifyObject(g)));
47 this.liveGames = localGames;
49 if (this.st.user.id > 0) {
50 ajax("/games", "GET", { uid: this.st.user.id }, res => {
51 res.games.forEach(g => (g.type = this.classifyObject(g)));
52 this.corrGames = res.games;
55 // Initialize connection
56 this.connexionString =
63 encodeURIComponent(this.$route.path);
64 this.conn = new WebSocket(this.connexionString);
65 this.conn.onmessage = this.socketMessageListener;
66 this.conn.onclose = this.socketCloseListener;
69 const showType = localStorage.getItem("type-myGames") || "live";
70 this.setDisplay(showType);
72 beforeDestroy: function() {
73 this.conn.send(JSON.stringify({code: "disconnect"}));
76 setDisplay: function(type, e) {
78 localStorage.setItem("type-myGames", type);
79 let elt = e ? e.target : document.getElementById(type + "Games");
80 elt.classList.add("active");
81 elt.classList.remove("somethingnew"); //in case of
82 if (elt.previousElementSibling)
83 elt.previousElementSibling.classList.remove("active");
84 else elt.nextElementSibling.classList.remove("active");
86 // TODO: classifyObject is redundant (see Hall.vue)
87 classifyObject: function(o) {
88 return o.cadence.indexOf("d") === -1 ? "live" : "corr";
90 showGame: function(g) {
91 this.$router.push("/game/" + g.id);
93 socketMessageListener: function(msg) {
94 const data = JSON.parse(msg.data);
95 if (data.code == "changeturn") {
96 let games = !!parseInt(data.gid)
99 // NOTE: new move itself is not received, because it wouldn't be used.
100 let g = games.find(g => g.id == data.gid);
101 this.$set(g, "movesCount", g.movesCount + 1);
103 (g.type == "live" && this.display == "corr") ||
104 (g.type == "corr" && this.display == "live")
107 .getElementById(g.type + "Games")
108 .classList.add("somethingnew");
112 socketCloseListener: function() {
113 this.conn = new WebSocket(this.connexionString);
114 this.conn.addEventListener("message", this.socketMessageListener);
115 this.conn.addEventListener("close", this.socketCloseListener);
126 background-color: #f9faee
132 background-color: #c5fefe !important