From: Benjamin Auder Date: Wed, 4 Dec 2019 10:26:36 +0000 (+0100) Subject: socket rooms correspnding to pages. TODO: Hall+Game (split live and corr? shared... X-Git-Url: https://git.auder.net/doc/html/%7B%7B%20path%28%27mixstore_user_admin_delete%27%2C%20%7B%20id:%20user.id%20%7D%29%20%7D%7D?a=commitdiff_plain;h=92a523d1a74cbabcfd7d6ade45f25fa622815f0b;p=vchess.git socket rooms correspnding to pages. TODO: Hall+Game (split live and corr? shared socket code?) --- diff --git a/client/src/App.vue b/client/src/App.vue index c5008f2e..a9c1d4cc 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -35,11 +35,10 @@ .row .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2 footer - a(href="https://github.com/yagu0/vchess") {{ st.tr["Source code"] }} + router-link.menuitem(to="/about") {{ st.tr["About"] }} p.clickable(onClick="doClick('modalContact')") - | {{ st.tr["Contact form"] }} - //my-game(:game-ref="gameRef" :mode="mode" :settings="settings" @game-over="archiveGame") - //// TODO: add only the necessary icons to mini-css custom build + | {{ st.tr["Contact"] }} + // TODO: add only the necessary icons to mini-css custom build //script(src="//unpkg.com/feather-icons") @@ -62,10 +61,6 @@ export default { st: store.state, }; }, -// // TODO: $route: ... -// gameRef: function() { -// this.loadGame(); -// }, computed: { flagImage: function() { return `/images/flags/${this.st.lang}.svg`; @@ -151,7 +146,7 @@ footer display: inline-flex align-items: center justify-content: center - & > a + & > .menuitem display: inline-block margin: 0 10px 0 0 &:link diff --git a/client/src/router.js b/client/src/router.js index 184fede0..380ccc6c 100644 --- a/client/src/router.js +++ b/client/src/router.js @@ -46,7 +46,7 @@ const router = new Router({ localStorage["myname"] = res.name; localStorage["myid"] = res.id; } - next(); + next("/"); } ); }, @@ -58,30 +58,26 @@ const router = new Router({ name: "game", component: loadView("Game"), }, -// { -// path: "/about", -// name: "about", -// // route level code-splitting -// // this generates a separate chunk (about.[hash].js) for this route -// // which is lazy-loaded when the route is visited. -// component: loadView('About'), -// //function() { -// // return import(/* webpackChunkName: "about" */ "./views/About.vue"); -// //} -// }, - // TODO: gameRef, problemId: https://router.vuejs.org/guide/essentials/dynamic-matching.html + { + path: "/about", + name: "about", + component: loadView("About"), + }, + // TODO: myGames, problemId: https://router.vuejs.org/guide/essentials/dynamic-matching.html ] }); router.beforeEach((to, from, next) => { - window.scrollTo(0, 0); //TODO: check if a live game is running; if yes, call next('/game') - //https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards + window.scrollTo(0, 0); + if (!!store.state.conn) //uninitialized at first page + { + // Notify WebSockets server (TODO: path or fullPath?) + store.state.conn.send(JSON.stringify({code: "pagechange", page: to.path})); + } next(); - //TODO: si une partie en cours dans storage, rediriger vers cette partie - //(à condition que l'URL n'y corresponde pas déjà !) - // (l'identifiant de l'utilisateur si connecté) -// if (!!localStorage["variant"]) -// location.hash = "#game?id=" + localStorage["gameId"]; + // TODO?: redirect to current game (through GameStorage.getCurrent()) if any? + // (and if the URL doesn't already match it) (use next("/game/GID")) + //https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards }); export default router; diff --git a/client/src/views/About.vue b/client/src/views/About.vue new file mode 100644 index 00000000..e4b76375 --- /dev/null +++ b/client/src/views/About.vue @@ -0,0 +1,36 @@ + + + diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 74dd01d2..d74002d6 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -27,15 +27,7 @@ // ==> après, implémenter/vérifier les passages de challenges + parties en cours // observer, // + problèmes, habiller et publier. (+ corr...) - // TODO: how to know who is observing ? Send message to everyone with game ID ? - // and then just listen to (dis)connect events - // server always send "connect on " + URL ; then add to observers if game... -// router when access a game page tell to server I joined + game ID (no need rid) -// and ask server for current joined (= observers) // when send to chat (or a move), reach only this group (send gid along) -// -> doivent être enregistrés comme observers au niveau du serveur... - // non: poll users + events startObserving / stopObserving - // (à faire au niveau du routeur ?) -->