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 => {
48 console.log(localGames);
50 localGames.forEach(g => (g.type = this.classifyObject(g)));
51 this.liveGames = localGames;
53 if (this.st.user.id > 0) {
54 ajax("/games", "GET", { uid: this.st.user.id }, res => {
55 res.games.forEach(g => (g.type = this.classifyObject(g)));
56 this.corrGames = res.games;
59 // Initialize connection
60 this.connexionString =
67 encodeURIComponent(this.$route.path);
68 this.conn = new WebSocket(this.connexionString);
69 this.conn.onmessage = this.socketMessageListener;
70 this.conn.onclose = this.socketCloseListener;
73 const showType = localStorage.getItem("type-myGames") || "live";
74 this.setDisplay(showType);
76 beforeDestroy: function() {
77 this.conn.send(JSON.stringify({code: "disconnect"}));
80 setDisplay: function(type, e) {
82 localStorage.setItem("type-myGames", type);
83 let elt = e ? e.target : document.getElementById(type + "Games");
84 elt.classList.add("active");
85 elt.classList.remove("somethingnew"); //in case of
86 if (elt.previousElementSibling)
87 elt.previousElementSibling.classList.remove("active");
88 else elt.nextElementSibling.classList.remove("active");
90 // TODO: classifyObject is redundant (see Hall.vue)
91 classifyObject: function(o) {
92 return o.cadence.indexOf("d") === -1 ? "live" : "corr";
94 showGame: function(g) {
95 this.$router.push("/game/" + g.id);
97 socketMessageListener: function(msg) {
98 const data = JSON.parse(msg.data);
99 // Only event is newmove, and received only:
100 if (data.code == "newmove") {
101 let games = !!parseInt(data.gid)
104 // NOTE: new move itself is not received, because it wouldn't be used.
105 let g = games.find(g => g.id == data.gid);
106 this.$set(g, "movesCount", g.movesCount + 1);
108 (g.type == "live" && this.display == "corr") ||
109 (g.type == "corr" && this.display == "live")
112 .getElementById(g.type + "Games")
113 .classList.add("somethingnew");
117 socketCloseListener: function() {
118 this.conn = new WebSocket(this.connexionString);
119 this.conn.addEventListener("message", this.socketMessageListener);
120 this.conn.addEventListener("close", this.socketCloseListener);
131 background-color: #f9faee
137 background-color: #c5fefe !important