Simplify navigation
[vchess.git] / public / javascripts / index.js
index 3d35c45..0e2a263 100644 (file)
@@ -5,10 +5,10 @@ new Vue({
                counts: {},
                curPrefix: "",
                conn: null,
+               display: "variants",
        },
        computed: {
                sortedCounts: function () {
-                       // TODO: priorité aux parties corr où c'est à nous de jouer !
                        const capitalizedPrefix = this.curPrefix.replace(/^\w/, c => c.toUpperCase());
                        const variantsCounts = variantArray
                        .filter( v => {
@@ -30,6 +30,9 @@ new Vue({
                },
        },
        created: function() {
+               this.setDisplay();
+               window.onhashchange = this.setDisplay;
+               
                const url = socketUrl;
                const sid = getRandString();
                this.conn = new WebSocket(url + "/?sid=" + sid + "&page=index");
@@ -38,9 +41,9 @@ new Vue({
                        if (data.code == "counts")
                                this.counts = data.counts;
                        else if (data.code == "increase")
-                               this.counts[data.vname]++;
+                               this.counts[data.vid]++;
                        else if (data.code == "decrease")
-                               this.counts[data.vname]--;
+                               this.counts[data.vid]--;
                };
                const socketCloseListener = () => {
                        this.conn = new WebSocket(url + "/?sid=" + sid + "&page=index");
@@ -50,9 +53,18 @@ new Vue({
                this.conn.onmessage = socketMessageListener;
                this.conn.onclose = socketCloseListener;
 
-               // TODO:
+               // TODO: AJAX call get corr games (all variants)
                // si dernier lastMove sur serveur n'est pas le mien et nextColor == moi, alors background orange
                // ==> background orange si à moi de jouer par corr (sur main index)
                // (helper: static fonction "GetNextCol()" dans base_rules.js)
+
+       },
+       methods: {
+               setDisplay: function() {
+                       if (!location.hash)
+                               location.hash = "#variants"; //default
+                       this.display = location.hash.substr(1);
+               },
+
        },
 });