X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fmain.js;h=46d99abec8e26ca48cdf57912d92c68099ed5ea2;hb=c66a829b3770122fe0ff2fb9db8def9635bbc334;hp=6651700495e46766de47bfa4ffdcf91dfb59d02f;hpb=ccd4a2b74aecdd6e52960a9ed42acea3e40c9271;p=vchess.git diff --git a/client/src/main.js b/client/src/main.js index 66517004..46d99abe 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -1,9 +1,8 @@ import Vue from "vue"; import App from "./App.vue"; import router from "./router"; -import params from "./parameters"; //for socket connection -import { ajax } from "./utils/ajax"; -import { util } from "./utils/misc"; +// Global store: see https://medium.com/fullstackio/managing-state-in-vue-js-23a0352b1c87 +import { store } from "./store"; Vue.config.productionTip = false; @@ -13,67 +12,37 @@ new Vue({ return h(App); }, // watch: { -// $lang: async function(newLang) { -// // Fill modalWelcome, and import translations from "./translations/$lang.js" -// document.getElementById("modalWelcome").innerHTML = -// require("raw-loader!pug-plain-loader!./modals/welcome/" + newLang + ".pug"); -// const tModule = await import("./translations/" + newLang + ".js"); -// Vue.prototype.$tr = tModule.translations; -// //console.log(tModule.translations); -// }, // $route: function(newRoute) { // //console.log(this.$route.params); // console.log("navig to " + newRoute); // //TODO: conn.send("enter", newRoute) // }, // }, - created: function() { - const supportedLangs = ["en","es","fr"]; - Vue.prototype.$lang = localStorage["lang"] || - supportedLangs.includes(navigator.language) - ? navigator.language - : "en"; - Vue.prototype.$variants = []; //avoid runtime error - ajax("/variants", "GET", res => { Vue.prototype.$variants = res.variantArray; }); - Vue.prototype.$tr = {}; //to avoid a compiler error - Vue.prototype.$user = {}; //TODO: from storage - // TODO: if there is a socket ID in localStorage, it means a live game was interrupted (and should resume) - const myid = localStorage["myid"] || util.getRandString(); - // NOTE: in this version, we don't say on which page we are, yet - // ==> we'll say "enter/leave" page XY (in fact juste "enter", seemingly) - Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid); - // Settings initialized with values from localStorage - Vue.prototype.$settings = { - bcolor: localStorage["bcolor"] || "lichess", - sound: parseInt(localStorage["sound"]) || 2, - hints: parseInt(localStorage["hints"]) || 1, - coords: !!eval(localStorage["coords"]), - highlight: !!eval(localStorage["highlight"]), - sqSize: parseInt(localStorage["sqSize"]), - }; - const socketCloseListener = () => { - Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid); - } - Vue.prototype.$conn.onclose = socketCloseListener; - //TODO: si une partie en cours dans storage, rediriger vers cette partie - //(à condition que l'URL n'y corresponde pas déjà !) - // TODO: à l'arrivée sur le site : set peerID (un identifiant unique - // en tout cas...) si pas trouvé dans localStorage "myid" - // (l'identifiant de l'utilisateur si connecté) -// if (!!localStorage["variant"]) -// location.hash = "#game?id=" + localStorage["gameId"]; - }, - // Later, for icons (if using feather): -// mounted: function() { -// feather.replace(); -// }, + created: function() { + window.doClick = (elemId) => { document.getElementById(elemId).click() }; + + //TODO: si une partie en cours dans storage, rediriger vers cette partie + //(à condition que l'URL n'y corresponde pas déjà !) + // TODO: à l'arrivée sur le site : set peerID (un identifiant unique + // en tout cas...) si pas trouvé dans localStorage "myid" + // (l'identifiant de l'utilisateur si connecté) +// if (!!localStorage["variant"]) +// location.hash = "#game?id=" + localStorage["gameId"]; + }, + // Later, for icons (if using feather): +// mounted: function() { +// feather.replace(); +// }, + mounted: function() { + store.initialize(); + }, }).$mount("#app"); // TODO: get rules, dynamic import // Load a rules page (AJAX) // router.get("/rules/:vname([a-zA-Z0-9]+)", access.ajax, (req,res) => { -// const lang = selectLanguage(req, res); -// res.render("rules/" + req.params["vname"] + "/" + lang); +// const lang = selectLanguage(req, res); +// res.render("rules/" + req.params["vname"] + "/" + lang); // }); // // board2, 3, 4 automatiquement, mais rules separement (les 3 pour une) @@ -81,7 +50,7 @@ new Vue({ // problems: on-demand // // See https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes -// created: function() { -// window.onhashchange = this.setDisplay; -// }, +// created: function() { +// window.onhashchange = this.setDisplay; +// }, //});