Index page almost OK. Now work on variant page (main hall...)
[vchess.git] / public / javascripts / index.js
index 12bcf64..6859e8b 100644 (file)
@@ -1,3 +1,4 @@
+// Javascript for index page: mostly counters updating
 new Vue({
        el: "#indexPage",
        data: {
@@ -7,7 +8,12 @@ new Vue({
        },
        computed: {
                sortedCounts: function () {
-                       const variantsCounts = variantArray.map( v => {
+                       // TODO: priorité aux parties corr où c'est à nous de jouer !
+                       const variantsCounts = variantArray
+                       .filter( v => {
+                               return v.name.startsWith(this.curPrefix);
+                       })
+                       .map( v => {
                                return {
                                        name: v.name,
                                        desc: v.description,
@@ -24,8 +30,7 @@ new Vue({
        },
        created: function() {
                const url = socketUrl;
-               // random enough (TODO: function)
-               const sid = (Date.now().toString(36) + Math.random().toString(36).substr(2, 7)).toUpperCase();
+               const sid = getRandString();
                this.conn = new WebSocket(url + "/?sid=" + sid + "&page=index");
                const socketMessageListener = msg => {
                        const data = JSON.parse(msg.data);
@@ -44,31 +49,36 @@ new Vue({
                this.conn.onmessage = socketMessageListener;
                this.conn.onclose = socketCloseListener;
        },
-       mounted: function() {
-               // Handle key stroke
-               document.onkeydown = event => {
-                       // Is it Back or Esc? If yes, apply action on current word
-                       if (event.keyCode == 8) //Back
-                       {
-                               event.preventDefault();
-                               this.curPrefix = this.curPrefix.slice(0,-1);
-                       }
-                       else if (event.keyCode == 27) //Esc
-                       {
-                               event.preventDefault();
-                               this.curPrefix = "";
-                       }
-                       // Is it alphanumeric? If yes, stack it
-                       else if (_.range(48,58).includes(event.keyCode)
-                               || _.range(65,91).includes(event.keyCode)
-                               || _.range(97,123).includes(event.keyCode))
-                       {
-                               let newChar = String.fromCharCode(event.keyCode);
-                               this.curPrefix += this.curPrefix.length==0
-                                       ? newChar.toUpperCase()
-                                       : newChar.toLowerCase();
-                       }
-                       // ...ignore everything else
-               };
-       },
+//     mounted: function() {
+//             // Handle key stroke
+//             document.onkeydown = event => {
+//                     // Is it Back or Esc? If yes, apply action on current word
+//                     if (event.keyCode == 8) //Back
+//                     {
+//                             event.preventDefault();
+//                             this.curPrefix = this.curPrefix.slice(0,-1);
+//                     }
+//                     else if (event.keyCode == 27) //Esc
+//                     {
+//                             event.preventDefault();
+//                             this.curPrefix = "";
+//                     }
+//                     // Is it alphanumeric? If yes, stack it
+//                     else if (_.range(48,58).includes(event.keyCode)
+//                             || _.range(65,91).includes(event.keyCode)
+//                             || _.range(97,123).includes(event.keyCode))
+//                     {
+//                             let newChar = String.fromCharCode(event.keyCode);
+//                             this.curPrefix += this.curPrefix.length==0
+//                                     ? newChar.toUpperCase()
+//                                     : newChar.toLowerCase();
+//                     }
+//                     // ...ignore everything else
+//             };
+//     },
 });
+
+// TODO:
+// 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)
+// (fonction "getNextCol()" dans base_rules.js ?)