Convert all remaining tabs by 2spaces
[vchess.git] / client / src / views / MyGames.vue
1 <template lang="pug">
2 main
3 .row
4 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
5 .button-group
6 button(@click="display='live'") Live games
7 button(@click="display='corr'") Correspondance games
8 GameList(v-show="display=='live'" :games="filterGames('live')"
9 @show-game="showGame")
10 GameList(v-show="display=='corr'" :games="filterGames('corr')"
11 @show-game="showGame")
12 </template>
13
14 <script>
15 import { store } from "@/store";
16 import { GameStorage } from "@/utils/gameStorage";
17 import { ajax } from "@/utils/ajax";
18 import GameList from "@/components/GameList.vue";
19
20 export default {
21 name: "my-games",
22 components: {
23 GameList,
24 },
25 data: function() {
26 return {
27 st: store.state,
28 display: "live",
29 games: [],
30 };
31 },
32 created: function() {
33 GameStorage.getAll((localGames) => {
34 localGames.forEach((g) => g.type = this.classifyObject(g));
35 //Array.prototype.push.apply(this.games, localGames); /TODO: Vue3...
36 this.games = this.games.concat(localGames);
37 });
38 if (this.st.user.id > 0)
39 {
40 ajax("/games", "GET", {uid: this.st.user.id}, (res) => {
41 res.games.forEach((g) => g.type = this.classifyObject(g));
42 //Array.prototype.push.apply(this.games, res.games); //TODO: Vue 3
43 this.games = this.games.concat(res.games);
44 });
45 }
46 },
47 methods: {
48 // TODO: classifyObject and filterGames are redundant (see Hall.vue)
49 classifyObject: function(o) {
50 return (o.timeControl.indexOf('d') === -1 ? "live" : "corr");
51 },
52 filterGames: function(type) {
53 return this.games.filter(g => g.type == type);
54 },
55 showGame: function(g) {
56 this.$router.push("/game/" + g.id);
57 },
58 },
59 };
60 </script>