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 GameList from "@/components/GameList.vue";
43 GameStorage.getAll(true, localGames => {
44 localGames.forEach(g => (g.type = this.classifyObject(g)));
45 this.liveGames = localGames;
47 if (this.st.user.id > 0) {
48 ajax("/games", "GET", { uid: this.st.user.id }, res => {
49 res.games.forEach(g => (g.type = this.classifyObject(g)));
50 this.corrGames = res.games;
53 // Initialize connection
54 this.connexionString =
61 encodeURIComponent(this.$route.path);
62 this.conn = new WebSocket(this.connexionString);
63 this.conn.onmessage = this.socketMessageListener;
64 this.conn.onclose = this.socketCloseListener;
67 const showType = localStorage.getItem("type-myGames") || "live";
68 this.setDisplay(showType);
71 setDisplay: function(type, e) {
73 localStorage.setItem("type-myGames", type);
74 let elt = e ? e.target : document.getElementById(type + "Games");
75 elt.classList.add("active");
76 if (elt.previousElementSibling)
77 elt.previousElementSibling.classList.remove("active");
78 else elt.nextElementSibling.classList.remove("active");
80 // TODO: classifyObject is redundant (see Hall.vue)
81 classifyObject: function(o) {
82 return o.cadence.indexOf("d") === -1 ? "live" : "corr";
84 showGame: function(g) {
85 this.$router.push("/game/" + g.id);
87 socketMessageListener: function(msg) {
88 const data = JSON.parse(msg.data);
89 // Only event is newmove, and received only:
90 if (data.code == "newmove") {
91 let games = !!parseInt(data.gid)
94 // NOTE: new move itself is not received, because it wouldn't be used.
95 let g = games.find(g => g.id == data.gid);
96 this.$set(g, "movesCount", g.movesCount + 1);
99 socketCloseListener: function() {
100 this.conn = new WebSocket(this.connexionString);
101 this.conn.addEventListener("message", this.socketMessageListener);
102 this.conn.addEventListener("close", this.socketCloseListener);
113 background-color: #f9faee