From 910d631b73cad5ffef1b4461157b704e7e7057d8 Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Tue, 18 Feb 2020 18:02:44 +0100 Subject: [PATCH] Some more cleaning + fixes --- client/package.json | 4 +- client/src/App.vue | 13 +-- client/src/base_rules.js | 3 +- client/src/components/BaseGame.vue | 24 +++--- client/src/components/ChallengeList.vue | 8 +- client/src/components/Chat.vue | 13 ++- client/src/components/ComputerGame.vue | 9 ++- client/src/components/ContactForm.vue | 13 ++- client/src/components/GameList.vue | 14 +++- client/src/components/Language.vue | 5 +- client/src/components/MoveList.vue | 62 +++++++++++++- client/src/components/Settings.vue | 15 +++- client/src/components/UpsertUser.vue | 42 ++++++++-- client/src/data/userCheck.js | 2 + client/src/store.js | 11 +-- client/src/utils/cookie.js | 8 +- client/src/utils/gameStorage.js | 2 +- client/src/variants/Grand.js | 1 - client/src/variants/Magnetic.js | 6 +- client/src/views/Analyse.vue | 10 ++- client/src/views/Auth.vue | 29 ++----- client/src/views/Game.vue | 51 +++++++++--- client/src/views/Hall.vue | 103 ++++++++++++++++++------ client/src/views/Logout.vue | 37 ++++----- client/src/views/MyGames.vue | 20 +++-- client/src/views/News.vue | 27 +++++-- client/src/views/Problems.vue | 22 ++++- client/src/views/Rules.vue | 34 ++++++-- client/src/views/Variants.vue | 7 +- server/sockets.js | 21 +++-- 30 files changed, 441 insertions(+), 175 deletions(-) diff --git a/client/package.json b/client/package.json index 88feedb9..172b5c4c 100644 --- a/client/package.json +++ b/client/package.json @@ -64,13 +64,13 @@ "flatTernaryExpressions": true } ], - "no-else-return" : [ + "no-else-return": [ 1, { "allowElseIf": false } ], - "semi" : [1, "always"] + "semi": [1, "always"] } }, "postcss": { diff --git a/client/src/App.vue b/client/src/App.vue index 9879e275..9c724e76 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -25,19 +25,22 @@ router-link(to="/problems") | {{ st.tr["Problems"] }} #rightMenu - .clickable(onClick="doClick('modalUser')") + .clickable(onClick="window.doClick('modalUser')") | {{ st.user.id > 0 ? (st.user.name || "@nonymous") : "Login" }} - .clickable(onClick="doClick('modalSettings')") + .clickable(onClick="window.doClick('modalSettings')") | {{ st.tr["Settings"] }} - .clickable#flagContainer(onClick="doClick('modalLang')") - img(v-if="!!st.lang" :src="flagImage") + .clickable#flagContainer(onClick="window.doClick('modalLang')") + img( + v-if="!!st.lang" + :src="flagImage" + ) router-view .row .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2 footer router-link.menuitem(to="/about") {{ st.tr["About"] }} router-link.menuitem(to="/news") {{ st.tr["News"] }} - p.clickable(onClick="doClick('modalContact')") + p.clickable(onClick="window.doClick('modalContact')") | {{ st.tr["Contact"] }} diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 056f4774..42d9bdc8 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -4,8 +4,8 @@ import { ArrayFun } from "@/utils/array"; import { randInt, shuffle } from "@/utils/alea"; +// class "PiPo": Piece + Position export const PiPo = class PiPo { - //Piece+Position // o: {piece[p], color[c], posX[x], posY[y]} constructor(o) { this.p = o.p; @@ -15,7 +15,6 @@ export const PiPo = class PiPo { } }; -// TODO: for animation, moves should contains "moving" and "fading" maybe... export const Move = class Move { // o: {appear, vanish, [start,] [end,]} // appear,vanish = arrays of PiPo diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index b2dd4a72..f4603d6b 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -52,7 +52,7 @@ div#baseGame( #downloadDiv(v-if="game.vname!='Dark' || game.score!='*'") a#download(href="#") button(@click="download()") {{ st.tr["Download"] }} PGN - button(onClick="doClick('modalAdjust')") ⤢ + button(onClick="window.doClick('modalAdjust')") ⤢ button( v-if="game.vname!='Dark' && game.mode!='analyze'" @click="analyzePosition()" @@ -169,7 +169,6 @@ export default { }, methods: { focusBg: function() { - // NOTE: small blue border appears... document.getElementById("baseGame").focus(); }, adjustBoard: function() { @@ -259,9 +258,9 @@ export default { this.game.vname + "/?fen=" + this.vr.getFen().replace(/ /g, "_"); + // Open in same tab in live games (against cheating) if (this.game.type == "live") this.$router.push(newUrl); - //open in same tab: against cheating... - else window.open("#" + newUrl); //open in a new tab: more comfortable + else window.open("#" + newUrl); }, download: function() { const content = this.getPgn(); @@ -305,9 +304,6 @@ export default { }, animateMove: function(move, callback) { let startSquare = document.getElementById(getSquareId(move.start)); - // TODO: error "flush nextTick callbacks" when observer reloads page: - // this late check is not a fix! - if (!startSquare) return; let endSquare = document.getElementById(getSquareId(move.end)); let rectStart = startSquare.getBoundingClientRect(); let rectEnd = endSquare.getBoundingClientRect(); @@ -318,9 +314,6 @@ export default { let movingPiece = document.querySelector( "#" + getSquareId(move.start) + " > img.piece" ); - if (!movingPiece) - //TODO: shouldn't happen - return; // HACK for animation (with positive translate, image slides "under background") // Possible improvement: just alter squares on the piece's way... const squares = document.getElementsByClassName("board"); @@ -330,7 +323,7 @@ export default { } movingPiece.style.transform = "translate(" + translation.x + "px," + translation.y + "px)"; - movingPiece.style.transitionDuration = "0.2s"; + movingPiece.style.transitionDuration = "0.25s"; movingPiece.style.zIndex = "3000"; setTimeout(() => { for (let i = 0; i < squares.length; i++) @@ -353,7 +346,8 @@ export default { return; } const doPlayMove = () => { - if (!!receive && this.cursor < this.moves.length - 1) this.gotoEnd(); //required to play the move + // To play a move, cursor must be at the end of the game: + if (!!receive && this.cursor < this.moves.length - 1) this.gotoEnd(); if (navigate) { if (this.cursor == this.moves.length - 1) return; //no more moves move = this.moves[this.cursor + 1]; @@ -433,6 +427,7 @@ export default { + + diff --git a/client/src/components/Settings.vue b/client/src/components/Settings.vue index e5a9d9c7..117133d1 100644 --- a/client/src/components/Settings.vue +++ b/client/src/components/Settings.vue @@ -1,17 +1,26 @@ - - diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index a0e264ed..9a971006 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -1,27 +1,51 @@ - - diff --git a/client/src/views/MyGames.vue b/client/src/views/MyGames.vue index 01b5264d..22f804dc 100644 --- a/client/src/views/MyGames.vue +++ b/client/src/views/MyGames.vue @@ -3,12 +3,20 @@ main .row .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2 .button-group - button.tabbtn#liveGames(@click="setDisplay('live',$event)") {{ st.tr["Live games"] }} - button.tabbtn#corrGames(@click="setDisplay('corr',$event)") {{ st.tr["Correspondance games"] }} - GameList(v-show="display=='live'" :games="liveGames" - @show-game="showGame") - GameList(v-show="display=='corr'" :games="corrGames" - @show-game="showGame") + button.tabbtn#liveGames(@click="setDisplay('live',$event)") + | {{ st.tr["Live games"] }} + button.tabbtn#corrGames(@click="setDisplay('corr',$event)") + | {{ st.tr["Correspondance games"] }} + GameList( + v-show="display=='live'" + :games="liveGames" + @show-game="showGame" + ) + GameList( + v-show="display=='corr'" + :games="corrGames" + @show-game="showGame" + )