From c143d96443098f5572d11a4171355cbdc010c5d8 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 20 Feb 2024 09:22:11 +0100 Subject: [PATCH] clean: respect es11 --- .jshintrc | 3 ++ frontend/static/js/api/LanguageManager.js | 6 +-- frontend/static/js/api/MyProfile.js | 6 +-- frontend/static/js/api/account.js | 2 +- frontend/static/js/api/chat/channel.js | 16 ++++---- frontend/static/js/api/chat/channels.js | 7 ++-- frontend/static/js/api/chat/message.js | 2 +- frontend/static/js/api/chat/notice.js | 38 +++++++++---------- frontend/static/js/api/client.js | 16 ++++---- frontend/static/js/api/game/Ball.js | 6 +-- frontend/static/js/api/game/Game.js | 10 ++--- frontend/static/js/api/game/MyPlayer.js | 4 +- frontend/static/js/api/game/Player.js | 4 +- frontend/static/js/api/game/Point.js | 8 ++-- frontend/static/js/api/game/Segment.js | 4 +- frontend/static/js/api/game/Time.js | 2 +- frontend/static/js/api/game/Wall.js | 6 +-- frontend/static/js/api/matchmaking.js | 8 ++-- frontend/static/js/api/profile.js | 14 +++---- frontend/static/js/api/profiles.js | 8 ++-- .../static/js/api/tournament/tournament.js | 10 ++--- .../static/js/api/tournament/tournaments.js | 6 +-- frontend/static/js/index.js | 14 +++---- frontend/static/js/views/GameOfflineView.js | 4 +- frontend/static/js/views/GameView.js | 4 +- frontend/static/js/views/HomeView.js | 2 +- frontend/static/js/views/MatchMakingView.js | 14 +++---- frontend/static/js/views/PageNotFoundView.js | 2 +- frontend/static/js/views/ProfilePageView.js | 14 +++---- frontend/static/js/views/Search.js | 34 ++++++++--------- frontend/static/js/views/SettingsView.js | 11 +++--- .../static/js/views/abstracts/AbstractView.js | 2 +- .../js/views/accounts/AuthenticationView.js | 11 +++--- .../views/tournament/TournamentCreateView.js | 6 +-- .../js/views/tournament/TournamentPageView.js | 10 ++--- .../views/tournament/TournamentsListView.js | 12 +++--- 36 files changed, 163 insertions(+), 163 deletions(-) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..cab3cdf --- /dev/null +++ b/.jshintrc @@ -0,0 +1,3 @@ +{ + "esversion": 11 +} \ No newline at end of file diff --git a/frontend/static/js/api/LanguageManager.js b/frontend/static/js/api/LanguageManager.js index e74724b..922a34a 100644 --- a/frontend/static/js/api/LanguageManager.js +++ b/frontend/static/js/api/LanguageManager.js @@ -1,11 +1,11 @@ -import { reloadView } from '../index.js' +import { reloadView } from '../index.js'; export default class LanguageManager { constructor() { this.availableLanguages = ['en', 'fr', 'tp', 'cr']; this.dict = null; - this.currentLang = 'en' + this.currentLang = 'en'; this.chosenLang = localStorage.getItem('preferedLanguage') || this.currentLang; if (this.chosenLang !== this.currentLang && this.availableLanguages.includes(this.chosenLang)) { this.loading = this.translatePage(); @@ -28,7 +28,7 @@ export default class LanguageManager { document.querySelectorAll('[data-i18n]').forEach(el => { let key = el.getAttribute('data-i18n'); el.innerHTML = this.dict[key]; - }) + }); await reloadView(); return 0; diff --git a/frontend/static/js/api/MyProfile.js b/frontend/static/js/api/MyProfile.js index fb4a9fd..9340d71 100644 --- a/frontend/static/js/api/MyProfile.js +++ b/frontend/static/js/api/MyProfile.js @@ -9,7 +9,7 @@ class MyProfile extends Profile */ constructor (client) { - super(client, "../me") + super(client, "../me"); } /** @@ -20,11 +20,11 @@ class MyProfile extends Profile async change_avatar(form_data) { let response = await this.client._patch_file(`/api/profiles/settings`, form_data); - let response_data = await response.json() + let response_data = await response.json(); return response_data; } } -export {MyProfile} +export {MyProfile}; diff --git a/frontend/static/js/api/account.js b/frontend/static/js/api/account.js index 61f96bd..9fb2308 100644 --- a/frontend/static/js/api/account.js +++ b/frontend/static/js/api/account.js @@ -86,4 +86,4 @@ class Account } } -export { Account } +export { Account }; diff --git a/frontend/static/js/api/chat/channel.js b/frontend/static/js/api/chat/channel.js index be0ef2a..a001c7b 100644 --- a/frontend/static/js/api/chat/channel.js +++ b/frontend/static/js/api/chat/channel.js @@ -1,4 +1,4 @@ -import {Message} from "./message.js" +import {Message} from "./message.js"; class Channel { constructor(client, channel_id, members_id, messages, reload) { @@ -18,7 +18,7 @@ class Channel { this.chatSocket = new WebSocket(url); this.chatSocket.onmessage = (event) =>{ - let data = JSON.parse(event.data) + let data = JSON.parse(event.data); this.messages.push(new Message( this.channel_id, @@ -41,12 +41,12 @@ class Channel { let new_messages = []; messages.forEach((message) => { - message = message["fields"]; + message = message.fields; new_messages.push(new Message( - message["channel_id"], - message["author_id"], - message["content"], - message["time"], + message.channel_id, + message.author_id, + message.content, + message.time, )); }); @@ -80,4 +80,4 @@ class Channel { } -export {Channel} +export {Channel}; diff --git a/frontend/static/js/api/chat/channels.js b/frontend/static/js/api/chat/channels.js index 84c50a3..49d767b 100644 --- a/frontend/static/js/api/chat/channels.js +++ b/frontend/static/js/api/chat/channels.js @@ -1,4 +1,4 @@ -import {Channel} from "./channel.js" +import {Channel} from "./channel.js"; class Channels { constructor(client) { @@ -17,7 +17,7 @@ class Channels { let data = await response.json(); - let messages = undefined; + let messages; if (response.status == 200) messages = data.messages; @@ -31,10 +31,9 @@ class Channels { }); let data = await response.json(); - console.log(response.status) return data; } } -export {Channels} +export {Channels}; diff --git a/frontend/static/js/api/chat/message.js b/frontend/static/js/api/chat/message.js index 4106512..c9532b7 100644 --- a/frontend/static/js/api/chat/message.js +++ b/frontend/static/js/api/chat/message.js @@ -7,4 +7,4 @@ class Message { } } -export {Message} +export {Message}; diff --git a/frontend/static/js/api/chat/notice.js b/frontend/static/js/api/chat/notice.js index f512d91..f7d5aaa 100644 --- a/frontend/static/js/api/chat/notice.js +++ b/frontend/static/js/api/chat/notice.js @@ -30,11 +30,11 @@ class Notice { console.log("receive_" + send.type + ": Function not found"); } - } + }; this.chatSocket.onopen = (event) => { this.getOnlineUser(); this.ask_friend(); - } + }; } async disconnect() { @@ -60,8 +60,8 @@ class Notice { async receive_accept_invite(send) { - this.data["invited"] = send.invites; - let id_game = send["id_game"]; + this.data.invited = send.invites; + let id_game = send.id_game; navigateTo("/game/" + id_game); } @@ -77,7 +77,7 @@ class Notice { } async receive_refuse_invite(send) { - this.data["invited"] = send.invites; + this.data.invited = send.invites; if (send.author_id == this.client.me.id) { if (this.rewrite_invite !== undefined) @@ -123,10 +123,10 @@ class Notice { // Regarder qu'il est bien invité par l'auteur // Et qu'il n'est pas déjà invité if (!content.includes(send.author_id) || - this.data["invited"].includes(send.author_id)) + this.data.invited.includes(send.author_id)) return; - this.data["invited"] = content; + this.data.invited = content; let sender = await this.client.profiles.getProfileId(send.author_id); create_popup("Invitation received by " + sender.username); @@ -152,24 +152,24 @@ class Notice { let content = send.online; if (content !== undefined) { - if (this.data["online"].length > 0) { + if (this.data.online.length > 0) { // get all disconnect user //let disconnects = this.data["online"].filter(id => !Object.keys(content).includes(id)); let disconnects = []; - for (const [key, value] of Object.entries(this.data["online"])) { + for (const [key, value] of Object.entries(this.data.online)) { if (content[key] == "red" && value == "green") disconnects.push(key); } // delete invite - this.data["invited"] = this.data["invited"].filter(id => !disconnects.includes(id)); + this.data.invited = this.data.invited.filter(id => !disconnects.includes(id)); //console.log(this.data["invited"]); } - this.data["online"] = content; + this.data.online = content; if (this.rewrite_usernames !== undefined) this.rewrite_usernames(); @@ -202,12 +202,12 @@ class Notice { //this.data["asker"].includes(send.author_id)) //return; - this.data["asked"] = send.asked; - this.data["asker"] = send.asker; + this.data.asked = send.asked; + this.data.asker = send.asker; if (send.author_id != my_id) { let sender = await this.client.profiles.getProfileId(send.author_id); - if (this.data["asker"].includes(send.author_id)) + if (this.data.asker.includes(send.author_id)) create_popup(sender.username + " ask you as friend"); if (this.rewrite_profile !== undefined) await this.rewrite_profile(); @@ -248,8 +248,8 @@ class Notice { } async receive_accept_friend(send) { - this.data["asked"] = send.asked; - this.data["asker"] = send.asker; + this.data.asked = send.asked; + this.data.asker = send.asker; let sender = await this.client.profiles.getProfileId(send.author_id); if (send.author_id == this.client.me.id) { @@ -279,8 +279,8 @@ class Notice { } async receive_refuse_friend(send) { - this.data["asked"] = send.asked; - this.data["asker"] = send.asker; + this.data.asked = send.asked; + this.data.asker = send.asker; let sender = await this.client.profiles.getProfileId(send.author_id); if (send.author_id == this.client.me.id) { @@ -304,4 +304,4 @@ class Notice { } } -export {Notice} +export {Notice}; diff --git a/frontend/static/js/api/client.js b/frontend/static/js/api/client.js index df0a7b1..33d82f0 100644 --- a/frontend/static/js/api/client.js +++ b/frontend/static/js/api/client.js @@ -3,11 +3,11 @@ import { MatchMaking } from "./matchmaking.js"; import { Profiles } from "./profiles.js"; import { Channels } from './chat/channels.js'; import { MyProfile } from "./MyProfile.js"; -import { navigateTo } from "../index.js" +import { navigateTo } from "../index.js"; import { Tourmanents } from "./tournament/tournaments.js"; -import {Notice} from "./chat/notice.js" +import {Notice} from "./chat/notice.js"; import { Channel } from "./chat/channel.js"; -import LanguageManager from './LanguageManager.js' +import LanguageManager from './LanguageManager.js'; function getCookie(name) { @@ -15,7 +15,7 @@ function getCookie(name) document.cookie.split(';').forEach(function(el) { let split = el.split('='); cookie[split[0].trim()] = split.slice(1).join("="); - }) + }); return cookie[name]; } @@ -72,7 +72,7 @@ class Client */ this.notice = new Notice(this); - this.lang = new LanguageManager; + this.lang = new LanguageManager(); } @@ -218,7 +218,7 @@ class Client */ async login(username, password) { - let response = await this._post("/api/accounts/login", {username: username, password: password}) + let response = await this._post("/api/accounts/login", {username: username, password: password}); if (response.status == 200) await this._update_logged(true); @@ -244,8 +244,8 @@ class Client let response = await this._get("/api/accounts/logged"); await this._update_logged(response.status === 200); - return response.status === 200 + return response.status === 200; } } -export {Client} +export {Client}; diff --git a/frontend/static/js/api/game/Ball.js b/frontend/static/js/api/game/Ball.js index dd8187d..267ad0b 100644 --- a/frontend/static/js/api/game/Ball.js +++ b/frontend/static/js/api/game/Ball.js @@ -55,7 +55,7 @@ class Ball */ render(ctx) { - let distance = this.speed * (this.game.time.deltaTime() / 1000) + let distance = this.speed * (this.game.time.deltaTime() / 1000); this.position.x = this.position.x + distance * Math.cos(this.angle); this.position.y = this.position.y - distance * Math.sin(this.angle); @@ -70,8 +70,8 @@ class Ball this.angle = data.angle; this.speed = data.speed; - return this + return this; } } -export { Ball } \ No newline at end of file +export { Ball }; \ No newline at end of file diff --git a/frontend/static/js/api/game/Game.js b/frontend/static/js/api/game/Game.js index 81dc406..2a7f136 100644 --- a/frontend/static/js/api/game/Game.js +++ b/frontend/static/js/api/game/Game.js @@ -1,6 +1,6 @@ import { sleep } from "../../utils/sleep.js"; import { Ball } from "./Ball.js"; -import { GameConfig } from "./GameConfig.js" +import { GameConfig } from "./GameConfig.js"; import { Player } from "./Player.js"; import { Time } from "./Time.js"; import { Wall } from "./Wall.js"; @@ -150,7 +150,7 @@ class Game if (data.detail === "update_paddle") this._receive_update_paddle(data); else if (data.detail === "update_ball") - this._receive_ball(data) + this._receive_ball(data); else if (data.detail === "init_game") this._init_game(data); } @@ -160,7 +160,7 @@ class Game /** * @type {Ball} */ - this.ball = (new Ball(this)).from_json(data.ball) + this.ball = (new Ball(this)).from_json(data.ball); /** * @type {[Wall]} @@ -174,7 +174,7 @@ class Game /** * @type {[Player]} */ - this.players = [] + this.players = []; const players_data = data.players; players_data.forEach((player_data) => { this.players.push(new Player(this).from_json(player_data)); @@ -216,4 +216,4 @@ class Game } } -export { Game } +export { Game }; diff --git a/frontend/static/js/api/game/MyPlayer.js b/frontend/static/js/api/game/MyPlayer.js index b0662ef..f7beb55 100644 --- a/frontend/static/js/api/game/MyPlayer.js +++ b/frontend/static/js/api/game/MyPlayer.js @@ -1,5 +1,5 @@ import { Player } from "./Player.js"; -import { Client } from "../client.js" +import { Client } from "../client.js"; import { Game } from "./Game.js"; import { Segment } from "./Segment.js"; @@ -66,4 +66,4 @@ class MyPlayer extends Player } } -export { MyPlayer } \ No newline at end of file +export { MyPlayer }; \ No newline at end of file diff --git a/frontend/static/js/api/game/Player.js b/frontend/static/js/api/game/Player.js index 000858f..a7eb437 100644 --- a/frontend/static/js/api/game/Player.js +++ b/frontend/static/js/api/game/Player.js @@ -115,8 +115,8 @@ class Player */ this.rail = this.rail.from_json(data.rail); - return this + return this; } } -export { Player } \ No newline at end of file +export { Player }; \ No newline at end of file diff --git a/frontend/static/js/api/game/Point.js b/frontend/static/js/api/game/Point.js index 3280668..1ee59d2 100644 --- a/frontend/static/js/api/game/Point.js +++ b/frontend/static/js/api/game/Point.js @@ -20,11 +20,11 @@ class Point from_json(data) { - this.x = data.x - this.y = data.y + this.x = data.x; + this.y = data.y; - return this + return this; } } -export { Point } \ No newline at end of file +export { Point }; \ No newline at end of file diff --git a/frontend/static/js/api/game/Segment.js b/frontend/static/js/api/game/Segment.js index 5c146e8..1dfc03a 100644 --- a/frontend/static/js/api/game/Segment.js +++ b/frontend/static/js/api/game/Segment.js @@ -1,4 +1,4 @@ -import { Point } from "./Point.js" +import { Point } from "./Point.js"; class Segment { @@ -54,4 +54,4 @@ class Segment } } -export { Segment } \ No newline at end of file +export { Segment }; \ No newline at end of file diff --git a/frontend/static/js/api/game/Time.js b/frontend/static/js/api/game/Time.js index 7edb1d7..5fe60c0 100644 --- a/frontend/static/js/api/game/Time.js +++ b/frontend/static/js/api/game/Time.js @@ -39,4 +39,4 @@ class Time } } -export { Time } \ No newline at end of file +export { Time }; \ No newline at end of file diff --git a/frontend/static/js/api/game/Wall.js b/frontend/static/js/api/game/Wall.js index be69f42..b860d81 100644 --- a/frontend/static/js/api/game/Wall.js +++ b/frontend/static/js/api/game/Wall.js @@ -20,10 +20,10 @@ class Wall from_json(data) { - this.rail = this.rail.from_json(data.rail) + this.rail = this.rail.from_json(data.rail); - return this + return this; } } -export { Wall } \ No newline at end of file +export { Wall }; \ No newline at end of file diff --git a/frontend/static/js/api/matchmaking.js b/frontend/static/js/api/matchmaking.js index 03063ca..d473fc1 100644 --- a/frontend/static/js/api/matchmaking.js +++ b/frontend/static/js/api/matchmaking.js @@ -10,7 +10,7 @@ class MatchMaking /** * @type {Client} */ - this.client = client + this.client = client; this.searching = false; } @@ -56,10 +56,10 @@ class MatchMaking async stop() { if (this._socket) - this._socket.close() - this._socket = undefined + this._socket.close(); + this._socket = undefined; this.searching = false; } } -export {MatchMaking} +export {MatchMaking}; diff --git a/frontend/static/js/api/profile.js b/frontend/static/js/api/profile.js index 65390e0..2504211 100644 --- a/frontend/static/js/api/profile.js +++ b/frontend/static/js/api/profile.js @@ -63,16 +63,16 @@ class Profile let block_response = await this.client._get("/api/profiles/block"); if (block_response.status != 200) - return + return; let block_data = await block_response.json(); - let block_list = JSON.parse(block_data["blockeds"]); - let client_id = block_data["user_id"]; + let block_list = JSON.parse(block_data.blockeds); + let client_id = block_data.user_id; block_list.forEach(block => { let blocker = block.fields.blocker; let blocked = block.fields.blocked; if (blocker == client_id && blocked == this.id) - return this.isBlocked = true; + return (this.isBlocked = true); }); } @@ -84,8 +84,8 @@ class Profile return this.isFriend; let friend_data = await friend_response.json(); - let friends_list = friend_data["friends"]; - let client_id = friend_data["user_id"]; + let friends_list = friend_data.friends; + let client_id = friend_data.user_id; friends_list.forEach(friend => { if (friend == this.id) { this.isFriend = true; @@ -97,4 +97,4 @@ class Profile } -export {Profile} +export {Profile}; diff --git a/frontend/static/js/api/profiles.js b/frontend/static/js/api/profiles.js index 8a00d8a..e995bef 100644 --- a/frontend/static/js/api/profiles.js +++ b/frontend/static/js/api/profiles.js @@ -10,7 +10,7 @@ class Profiles /** * @type {Client} client */ - this.client = client + this.client = client; } /** @@ -22,9 +22,9 @@ class Profiles let response = await this.client._get("/api/profiles/"); let response_data = await response.json(); - let profiles = [] + let profiles = []; response_data.forEach((profile) => { - profiles.push(new Profile(this.client, profile.username, profile.user_id, profile.avatar)) + profiles.push(new Profile(this.client, profile.username, profile.user_id, profile.avatar)); }); return profiles; } @@ -85,4 +85,4 @@ class Profiles } } -export {Profiles} +export {Profiles}; diff --git a/frontend/static/js/api/tournament/tournament.js b/frontend/static/js/api/tournament/tournament.js index bbba2d8..00de622 100644 --- a/frontend/static/js/api/tournament/tournament.js +++ b/frontend/static/js/api/tournament/tournament.js @@ -65,7 +65,7 @@ class Tourmanent /** * @type {Number} */ - this.id = id + this.id = id; /** * @type {Boolean} if a websocket connection is enabled @@ -99,16 +99,16 @@ class Tourmanent leave(event) { if (this.connected == false) - return + return; this.connected = false; - this._socket.close() + this._socket.close(); this.disconnect_func(event); } toggle_participation() { if (!this.connected) - return + return; this._socket.send(JSON.stringify({participate: ""})); } @@ -143,4 +143,4 @@ class Tourmanent } -export { Tourmanent } +export { Tourmanent }; diff --git a/frontend/static/js/api/tournament/tournaments.js b/frontend/static/js/api/tournament/tournaments.js index 9f00564..b56ea5e 100644 --- a/frontend/static/js/api/tournament/tournaments.js +++ b/frontend/static/js/api/tournament/tournaments.js @@ -11,7 +11,7 @@ class Tourmanents /** * @type {Client} */ - this.client = client + this.client = client; } /** @@ -52,7 +52,7 @@ class Tourmanents async search(state) { let response = await this.client._get(`/api/tournaments/search/${state}`); - let response_data = await response.json() + let response_data = await response.json(); if (response.status === 403) { @@ -88,4 +88,4 @@ class Tourmanents } -export { Tourmanents } \ No newline at end of file +export { Tourmanents }; \ No newline at end of file diff --git a/frontend/static/js/index.js b/frontend/static/js/index.js index 585ae8c..a58e1ce 100644 --- a/frontend/static/js/index.js +++ b/frontend/static/js/index.js @@ -7,7 +7,7 @@ import LogoutView from "./views/accounts/LogoutView.js"; import GameOfflineView from "./views/GameOfflineView.js"; import GameView from "./views/GameView.js"; -import PageNotFoundView from './views/PageNotFoundView.js' +import PageNotFoundView from './views/PageNotFoundView.js' ; import AbstractRedirectView from "./views/abstracts/AbstractRedirectView.js"; import SettingsView from "./views/SettingsView.js"; @@ -21,8 +21,8 @@ import AuthenticationView from "./views/accounts/AuthenticationView.js"; let client = new Client(location.origin); let lang = client.lang; -let lastView = undefined; -let lastPageUrlBeforeLogin = undefined; +let lastView; +let lastPageUrlBeforeLogin; const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$"); @@ -52,7 +52,7 @@ const navigateTo = async (uri) => { const reloadView = async _ => { await lastView?.leavePage(); await renderView(lastView); -} +}; async function renderView(view) { @@ -61,7 +61,7 @@ async function renderView(view) return 1; view.setTitle(); - document.querySelector("#app").innerHTML = content + document.querySelector("#app").innerHTML = content; let error_code = await view.postInit(); @@ -129,7 +129,7 @@ const router = async(uri) => { return 0; }; -window.addEventListener("popstate", function() {router(location.pathname)}); +window.addEventListener("popstate", function() {router(location.pathname);}); document.addEventListener("DOMContentLoaded", async () => { document.body.addEventListener("click", e => { @@ -162,4 +162,4 @@ document.addEventListener("DOMContentLoaded", async () => { document.querySelector('a[href=\'' + location.pathname + '\']')?.classList.add('active'); }); -export { client, lang, navigateTo, reloadView } +export { client, lang, navigateTo, reloadView }; diff --git a/frontend/static/js/views/GameOfflineView.js b/frontend/static/js/views/GameOfflineView.js index a7dc96e..e4761b3 100644 --- a/frontend/static/js/views/GameOfflineView.js +++ b/frontend/static/js/views/GameOfflineView.js @@ -26,13 +26,13 @@ export default class extends AbstractView { startGame() { if (this.game == null) { document.getElementById('startGameButton').innerHTML = 'Reset Game'; - this.game = new Game; + this.game = new Game(); } else { document.getElementById('app').removeChild(this.game.canvas); document.getElementById('app').removeChild(this.game.scoresDisplay); this.game.cleanup(); - this.game = new Game; + this.game = new Game(); } } diff --git a/frontend/static/js/views/GameView.js b/frontend/static/js/views/GameView.js index 11f5580..86b92df 100644 --- a/frontend/static/js/views/GameView.js +++ b/frontend/static/js/views/GameView.js @@ -77,7 +77,7 @@ export default class extends AbstractView async join_game() { - await this.game.join() + await this.game.join(); let canva = document.createElement("canvas"); @@ -100,7 +100,7 @@ export default class extends AbstractView this.game.players[index] = this.my_player; } - this.register_key() + this.register_key(); this.render(); } diff --git a/frontend/static/js/views/HomeView.js b/frontend/static/js/views/HomeView.js index 6ff6b0e..1724176 100644 --- a/frontend/static/js/views/HomeView.js +++ b/frontend/static/js/views/HomeView.js @@ -4,7 +4,7 @@ import AbstractAuthenticatedView from "./abstracts/AbstractAuthenticatedView.js" export default class extends AbstractAuthenticatedView { constructor(params) { super(params, 'homeWindowTitle'); - this.redirect_url = "/login" + this.redirect_url = "/login"; } async getHtml() { diff --git a/frontend/static/js/views/MatchMakingView.js b/frontend/static/js/views/MatchMakingView.js index 0414fa2..8acadd6 100644 --- a/frontend/static/js/views/MatchMakingView.js +++ b/frontend/static/js/views/MatchMakingView.js @@ -13,23 +13,23 @@ export default class extends AbstractAuthenticatedView { if (client.matchmaking.searching) { client.matchmaking.stop(); - document.getElementById("button").value = "Find a game" + document.getElementById("button").value = "Find a game"; } else { - let nb_players = document.getElementById("nb_players-input").value + let nb_players = document.getElementById("nb_players-input").value; await client.matchmaking.start(this.onreceive.bind(this), this.ondisconnect.bind(this), nb_players); - document.getElementById("button").value = "Stop matchmaking" + document.getElementById("button").value = "Stop matchmaking"; } } ondisconnect(event) { if (event.code === 1000) - clear("innerText", ["detail"]) - document.getElementById("button").value = "Find a game" + clear("innerText", ["detail"]); + document.getElementById("button").value = "Find a game"; } onreceive(data) @@ -39,7 +39,7 @@ export default class extends AbstractAuthenticatedView { navigateTo(`/games/${data.game_id}`); return; } - this.display_data(data) + this.display_data(data); } display_data(data) @@ -50,7 +50,7 @@ export default class extends AbstractAuthenticatedView { async postInit() { - document.getElementById("button").onclick = this.press_button.bind(this) + document.getElementById("button").onclick = this.press_button.bind(this); } async getHtml() { diff --git a/frontend/static/js/views/PageNotFoundView.js b/frontend/static/js/views/PageNotFoundView.js index 01a8ef3..885e735 100644 --- a/frontend/static/js/views/PageNotFoundView.js +++ b/frontend/static/js/views/PageNotFoundView.js @@ -1,5 +1,5 @@ import AbstractView from "./abstracts/AbstractView.js"; -import { lang } from '../index.js' +import { lang } from '../index.js'; export default class extends AbstractView { constructor(params) { diff --git a/frontend/static/js/views/ProfilePageView.js b/frontend/static/js/views/ProfilePageView.js index 7f69a64..3b70262 100644 --- a/frontend/static/js/views/ProfilePageView.js +++ b/frontend/static/js/views/ProfilePageView.js @@ -1,5 +1,5 @@ import AbstractView from "./abstracts/AbstractView.js"; -import { client, lang } from "../index.js" +import { client, lang } from "../index.js"; export default class extends AbstractView { constructor(params) { @@ -37,9 +37,9 @@ export default class extends AbstractView { client.notice.rewrite_profile = async () => { let result = await this.profile.getFriend(); - await this.profile.getBlock() + await this.profile.getBlock(); await this.friendButton(); - } + }; } async blockButton() { @@ -80,7 +80,7 @@ export default class extends AbstractView { let no = document.getElementById("no") || document.createElement("p"); let friend = document.getElementById("friend") || document.createElement("p"); - if (client.notice.data["asker"].includes(this.user_id)) { + if (client.notice.data.asker.includes(this.user_id)) { if (friend) friend.remove(); @@ -89,13 +89,13 @@ export default class extends AbstractView { yes.textContent = lang.get('profileAcceptRequest', 'Accept Friend'); yes.onclick = async () => { client.notice.accept_friend(this.user_id); - } + }; no.id = "no"; no.textContent = lang.get('profileDenyRequest', 'Decline Friend'); no.onclick = async () => { client.notice.refuse_friend(this.user_id); - } + }; this.info.appendChild(yes); this.info.appendChild(document.createTextNode(" ")); @@ -107,7 +107,7 @@ export default class extends AbstractView { if (yes && no) yes.remove(); no.remove(); - friend.id = "friend" + friend.id = "friend"; friend.onclick = async () => { if (this.profile.isFriend) await client.notice.remove_friend(this.user_id); diff --git a/frontend/static/js/views/Search.js b/frontend/static/js/views/Search.js index 9911f1a..abd0594 100644 --- a/frontend/static/js/views/Search.js +++ b/frontend/static/js/views/Search.js @@ -1,6 +1,6 @@ import AbstractView from "./abstracts/AbstractView.js"; import { client, lang } from "../index.js"; -import {Message} from "../api/chat/message.js" +import {Message} from "../api/chat/message.js"; export default class extends AbstractView { constructor(params) { @@ -10,8 +10,8 @@ export default class extends AbstractView { async wait_get_online_users() { return new Promise((resolve) => { const checkInterval = setInterval(() => { - console.log(client.notice.data["online"]); - if (Object.keys(client.notice.data["online"]).length > 0) { + console.log(client.notice.data.online); + if (Object.keys(client.notice.data.online).length > 0) { clearInterval(checkInterval); resolve(); } @@ -25,7 +25,7 @@ export default class extends AbstractView { let profiles = await client.profiles.all(); //console.log(client.notice.data); - if (client.notice.data == undefined || client.notice.data["online"] == undefined) + if (client.notice.data == undefined || client.notice.data.online == undefined) return console.log("Error"); //await client.notice.getOnlineUser(); @@ -66,12 +66,12 @@ export default class extends AbstractView { // username let username = document.createElement("a"); username.setAttribute('data-link', ''); - username.id = `username${user.id}` + username.id = `username${user.id}`; username.href = `/profiles/${user.username}`; if (logged && user.id == client.me.id) username.style.color = "green"; else { - let online = client.notice.data["online"][user.id]; + let online = client.notice.data.online[user.id]; username.style.color = online !== undefined ? online : "gray"; } username.appendChild(document.createTextNode(user.username)); @@ -134,7 +134,7 @@ export default class extends AbstractView { let search_document = document.getElementById("input_user"); if (search_document == undefined || search_document == null) - return + return; let search = search_document.value.toLowerCase(); @@ -146,7 +146,7 @@ export default class extends AbstractView { if (user.id == client.me.id) username.style.color = "green"; else { - let online = client.notice.data["online"][user.id]; + let online = client.notice.data.online[user.id]; username.style.color = online !== undefined ? online : "gray"; } } @@ -233,7 +233,7 @@ export default class extends AbstractView { messages.appendChild(text); }); - return messages + return messages; } async reload_display_messages() { @@ -274,7 +274,7 @@ export default class extends AbstractView { chat.appendChild(members); - return members + return members; } async display_invite() { @@ -291,9 +291,9 @@ export default class extends AbstractView { let yes = document.getElementById("yes") || document.createElement("button"); let no = document.getElementById("no") || document.createElement("button"); - let invitedBy = undefined; + let invitedBy; for (let x in others) { - if (client.notice.data["invited"].includes(others[x])) { + if (client.notice.data.invited.includes(others[x])) { invitedBy = others[x]; } } @@ -309,7 +309,7 @@ export default class extends AbstractView { invite.id = "invite"; invite.style.background = "orange"; invite.innerText = "invite"; - invite.title = "Invite to play a game" + invite.title = "Invite to play a game"; invite.onclick = async () => { await client.notice.send_invite(others); }; @@ -318,18 +318,18 @@ export default class extends AbstractView { else { if (invite) - invite.remove() + invite.remove(); yes.id = "yes"; yes.style.background = "green"; - yes.title = "Accept to play a game" + yes.title = "Accept to play a game"; yes.onclick = async () => { await client.notice.accept_invite(invitedBy); }; no.id = "no"; no.style.background = "red"; - no.title = "Refuse to play a game" + no.title = "Refuse to play a game"; no.onclick = async () => { await client.notice.refuse_invite(invitedBy); }; @@ -342,7 +342,7 @@ export default class extends AbstractView { async hide_chat() { - let closes = ["chat", "invite"] + let closes = ["chat", "invite"]; closes.forEach(close => { if (document.getElementById(close)) document.getElementById(close).remove(); diff --git a/frontend/static/js/views/SettingsView.js b/frontend/static/js/views/SettingsView.js index 5f2ceff..0c6630b 100644 --- a/frontend/static/js/views/SettingsView.js +++ b/frontend/static/js/views/SettingsView.js @@ -36,14 +36,13 @@ export default class extends AbstractAuthenticatedView let response_data = await client.account.delete(current_password); - console.log(await client.isAuthenticated()) if (response_data === null || response_data === "user deleted") { navigateTo("/login"); return; } - clear("innerHTML", ["current_password-input"]) - fill_errors({"current_password-input": response_data["password"]}, "innerHTML") + clear("innerHTML", ["current_password-input"]); + fill_errors({"current_password-input": response_data.password}, "innerHTML"); } async save_account() @@ -67,10 +66,10 @@ export default class extends AbstractAuthenticatedView } if (response_data === "data has been alterate") - response_data = {"save-account": "saved"} + response_data = {"save-account": "saved"}; - clear("innerHTML", ["username", "new_password", "current_password", "save-account", "delete-account"]) - fill_errors(response_data, "innerHTML") + clear("innerHTML", ["username", "new_password", "current_password", "save-account", "delete-account"]); + fill_errors(response_data, "innerHTML"); } async save_profile() diff --git a/frontend/static/js/views/abstracts/AbstractView.js b/frontend/static/js/views/abstracts/AbstractView.js index f94769b..e16dcd4 100644 --- a/frontend/static/js/views/abstracts/AbstractView.js +++ b/frontend/static/js/views/abstracts/AbstractView.js @@ -1,4 +1,4 @@ -import {lang} from '../../index.js' +import {lang} from '../../index.js'; export default class { constructor(params, titleKey) { diff --git a/frontend/static/js/views/accounts/AuthenticationView.js b/frontend/static/js/views/accounts/AuthenticationView.js index ed3d233..412d878 100644 --- a/frontend/static/js/views/accounts/AuthenticationView.js +++ b/frontend/static/js/views/accounts/AuthenticationView.js @@ -8,7 +8,6 @@ export default class extends AbstractNonAuthenticatedView { super(params, 'loginWindowTitle', lastUrlBeforeLogin); this.redirect_url = lastUrlBeforeLogin; - this.current_mode = undefined } async leavePage() @@ -36,7 +35,7 @@ export default class extends AbstractNonAuthenticatedView [username_input, password_input].forEach(input => { input.addEventListener('keydown', async ev => { if (ev.key === 'Enter') - await this.authentication.bind(this)() + await this.authentication.bind(this)(); }); }); username_input.focus(); @@ -59,7 +58,7 @@ export default class extends AbstractNonAuthenticatedView if (username === '' || password === '') return false; - return true + return true; } /** @@ -102,7 +101,7 @@ export default class extends AbstractNonAuthenticatedView password_label.innerText = lang.get(password_label_text, "ERROR LANG"); let toggle_register_login_label_text = this.current_mode === "register" ? "registerAlreadyAccount" : "loginNoAccount"; - toggle_register_login_label.innerText = lang.get(toggle_register_login_label_text, "ERROR LANG");; + toggle_register_login_label.innerText = lang.get(toggle_register_login_label_text, "ERROR LANG"); let toggle_register_login_text = this.current_mode === "register" ? "registerLogin" : "loginRegister"; toggle_register_login.innerText = lang.get(toggle_register_login_text, "ERROR LANG"); @@ -130,7 +129,7 @@ export default class extends AbstractNonAuthenticatedView let response; if (this.current_mode === "register") - response = await client.account.create(username, password) + response = await client.account.create(username, password); else response = await client.login(username, password); @@ -140,7 +139,7 @@ export default class extends AbstractNonAuthenticatedView return; } - let response_data = await response.json() + let response_data = await response.json(); console.log(response_data); diff --git a/frontend/static/js/views/tournament/TournamentCreateView.js b/frontend/static/js/views/tournament/TournamentCreateView.js index 8983071..ffd7690 100644 --- a/frontend/static/js/views/tournament/TournamentCreateView.js +++ b/frontend/static/js/views/tournament/TournamentCreateView.js @@ -14,14 +14,14 @@ export default class extends AbstractAuthenticatedView { let name = document.getElementById("name-input").value; let nb_players = document.getElementById("nb_players-input").value; - let nb_players_by_game = document.getElementById("nb_players_by_game-input").value + let nb_players_by_game = document.getElementById("nb_players_by_game-input").value; let response_data = await client.tournaments.createTournament(nb_players, nb_players_by_game, name); if (response_data === null) return; - let id = response_data["id"] + let id = response_data.id; if (id !== undefined) { navigateTo(`/tournaments/${id}`); @@ -47,6 +47,6 @@ export default class extends AbstractAuthenticatedView - ` + `; } } diff --git a/frontend/static/js/views/tournament/TournamentPageView.js b/frontend/static/js/views/tournament/TournamentPageView.js index 2d66bfa..9081c48 100644 --- a/frontend/static/js/views/tournament/TournamentPageView.js +++ b/frontend/static/js/views/tournament/TournamentPageView.js @@ -17,13 +17,13 @@ export default class extends AbstractAuthenticatedView async receive(data) { if (data.detail === "nb_participants" || data.detail === "update_participants") - document.getElementById("nb_participants").innerText = `${data.nb_participants} / ${this.tournament.nb_players}` + document.getElementById("nb_participants").innerText = `${data.nb_participants} / ${this.tournament.nb_players}`; if (data.detail === "go_to") navigateTo(data.url); if (data.detail === "is_participant") - this.updateParticipating(data.is_participant) + this.updateParticipating(data.is_participant); if (data.detail === "error") - document.getElementById("display").innerText = data.error_message + document.getElementById("display").innerText = data.error_message; } async updateParticipating(state) @@ -45,7 +45,7 @@ export default class extends AbstractAuthenticatedView this.tournament.join(this.receive.bind(this), this.ondisconnect.bind(this)); - let button = document.getElementById("button") + let button = document.getElementById("button"); button.onclick = this.pressButton.bind(this); @@ -93,6 +93,6 @@ export default class extends AbstractAuthenticatedView - ` + `; } } diff --git a/frontend/static/js/views/tournament/TournamentsListView.js b/frontend/static/js/views/tournament/TournamentsListView.js index eae0451..5ce9559 100644 --- a/frontend/static/js/views/tournament/TournamentsListView.js +++ b/frontend/static/js/views/tournament/TournamentsListView.js @@ -17,14 +17,14 @@ export default class extends AbstractAuthenticatedView add_nb_player_by_game_selector() { - let nb_players_by_game_list = new Set() + let nb_players_by_game_list = new Set(); this.tournaments.forEach(tournament => { nb_players_by_game_list.add(tournament.nb_players_by_game); }); let select = document.getElementById("nb-players-by-game-select"); - let new_children = [] + let new_children = []; const opt = document.createElement("option"); opt.value = "all"; @@ -37,7 +37,7 @@ export default class extends AbstractAuthenticatedView opt.value = nb_players_by_game; opt.text = nb_players_by_game; new_children.push(opt); - }) + }); select.replaceChildren(...new_children); } @@ -56,7 +56,7 @@ export default class extends AbstractAuthenticatedView { const tournaments_list = document.getElementById("tournaments-list"); - const new_children = [] + const new_children = []; this.display_tournaments.forEach(tournament => { @@ -102,7 +102,7 @@ export default class extends AbstractAuthenticatedView async postInit() { - await this.update_search() + await this.update_search(); document.getElementById("state-select").onchange = this.update_search.bind(this); document.getElementById("nb-players-by-game-select").onchange = this.update_query.bind(this); } @@ -128,6 +128,6 @@ export default class extends AbstractAuthenticatedView - ` + `; } }