From 45a2721c5c80fc3351b0abe8c7ef63d93f701977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 13 Oct 2020 17:20:20 +0200 Subject: [PATCH] Fixing code post rebase --- front/src/Connexion/ConnectionManager.ts | 18 +++++++++++------- front/src/Url/UrlManager.ts | 7 +++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index fe30ec23..c3b4c39b 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -31,7 +31,7 @@ class ConnectionManager { const room = new Room(window.location.pathname); return Promise.resolve(room); - } else if (connexionType === GameConnexionTypes.anonymous) { + } else if (connexionType === GameConnexionTypes.anonymous || connexionType === GameConnexionTypes.empty) { const localUser = localUserStore.getLocalUser(); if (localUser && localUser.jwtToken && localUser.uuid) { @@ -41,7 +41,14 @@ class ConnectionManager { this.localUser = new LocalUser(data.userUuid, data.authToken); localUserStore.saveUser(this.localUser); } - const room = new Room(window.location.pathname); + let roomId: string + if (connexionType === GameConnexionTypes.empty) { + const defaultMapUrl = window.location.host.replace('play.', 'maps.') + URL_ROOM_STARTED; + roomId = urlManager.editUrlForRoom(defaultMapUrl, null, null); + } else { + roomId = window.location.pathname; + } + const room = new Room(roomId); return Promise.resolve(room); } else if (connexionType == GameConnexionTypes.organization) { const localUser = localUserStore.getLocalUser(); @@ -55,11 +62,8 @@ class ConnectionManager { return Promise.reject('Could not find a user in localstorage'); } } - - //todo: cleaner way to handle the default case - const defaultMapUrl = window.location.host.replace('api.', 'maps.') + URL_ROOM_STARTED; - const defaultRoomId = urlManager.editUrlForRoom(URL_ROOM_STARTED, null, null); - return Promise.resolve(new Room(defaultRoomId, defaultMapUrl)); + + return Promise.reject('Invalid URL'); } public initBenchmark(): void { diff --git a/front/src/Url/UrlManager.ts b/front/src/Url/UrlManager.ts index fb7157c8..f7eeacce 100644 --- a/front/src/Url/UrlManager.ts +++ b/front/src/Url/UrlManager.ts @@ -3,6 +3,7 @@ export enum GameConnexionTypes { anonymous=1, organization, register, + empty, unknown, } @@ -17,9 +18,11 @@ class UrlManager { } else if (url.includes('@/')) { return GameConnexionTypes.organization; } else if(url.includes('register/')) { - return GameConnexionTypes.register + return GameConnexionTypes.register; + } else if(url === '/') { + return GameConnexionTypes.empty; } else { - return GameConnexionTypes.unknown + return GameConnexionTypes.unknown; } }