Fix games list display + challenges display
[vchess.git] / client / src / views / MyGames.vue
CommitLineData
afd3240d
BA
1<template lang="pug">
2main
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>
afd3240d
BA
15import { store } from "@/store";
16import { GameStorage } from "@/utils/gameStorage";
17import { ajax } from "@/utils/ajax";
18import GameList from "@/components/GameList.vue";
0b0dc040 19
afd3240d
BA
20export 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);
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) {
49 return (o.timeControl.indexOf('d') === -1 ? "live" : "corr");
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>
60
afd3240d
BA
61<style scoped lang="sass">
62/* TODO */
63</style>