Commit | Line | Data |
---|---|---|
afd3240d BA |
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 | |
602d6bef BA |
6 | button(@click="display='live'") {{ st.tr["Live games"] }} |
7 | button(@click="display='corr'") {{ st.tr["Correspondance games"] }} | |
afd3240d BA |
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> | |
afd3240d BA |
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 | export default { | |
20 | name: "my-games", | |
21 | components: { | |
22 | GameList, | |
23 | }, | |
24 | data: function() { | |
25 | return { | |
26 | st: store.state, | |
dac39588 | 27 | display: "live", |
afd3240d BA |
28 | games: [], |
29 | }; | |
30 | }, | |
31 | created: function() { | |
32 | GameStorage.getAll((localGames) => { | |
33 | localGames.forEach((g) => g.type = this.classifyObject(g)); | |
77c50966 | 34 | //Array.prototype.push.apply(this.games, localGames); //TODO: Vue 3 |
25d18342 | 35 | this.games = this.games.concat(localGames); |
afd3240d BA |
36 | }); |
37 | if (this.st.user.id > 0) | |
38 | { | |
39 | ajax("/games", "GET", {uid: this.st.user.id}, (res) => { | |
40 | res.games.forEach((g) => g.type = this.classifyObject(g)); | |
41 | //Array.prototype.push.apply(this.games, res.games); //TODO: Vue 3 | |
42 | this.games = this.games.concat(res.games); | |
43 | }); | |
44 | } | |
45 | }, | |
46 | methods: { | |
47 | // TODO: classifyObject and filterGames are redundant (see Hall.vue) | |
48 | classifyObject: function(o) { | |
71468011 | 49 | return (o.cadence.indexOf('d') === -1 ? "live" : "corr"); |
afd3240d BA |
50 | }, |
51 | filterGames: function(type) { | |
52 | return this.games.filter(g => g.type == type); | |
53 | }, | |
54 | showGame: function(g) { | |
afd3240d BA |
55 | this.$router.push("/game/" + g.id); |
56 | }, | |
57 | }, | |
58 | }; | |
59 | </script> |