From c05083e1495d749d1ed14efb417b489a83a21f97 Mon Sep 17 00:00:00 2001 From: ThunderDev1 Date: Tue, 3 Dec 2019 23:37:39 +0100 Subject: [PATCH] Change host assignment The host is now the oldest member of the lobby --- client/src/components/PlayerBox/PlayerBox.scss | 1 + client/src/pages/Index.tsx | 1 - client/src/pages/Lobby/Lobby.scss | 2 +- client/src/pages/Lobby/Lobby.tsx | 13 +++++++------ client/src/utils/signalrConnector.ts | 5 ----- server/DTO/GameDTOs.cs | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/client/src/components/PlayerBox/PlayerBox.scss b/client/src/components/PlayerBox/PlayerBox.scss index dfcb76a..3ae440f 100644 --- a/client/src/components/PlayerBox/PlayerBox.scss +++ b/client/src/components/PlayerBox/PlayerBox.scss @@ -7,5 +7,6 @@ $background-color: rgb(37, 153, 138); background-color: $background-color; color: white; padding: 1rem; + margin: 1rem; min-width: 10rem; } diff --git a/client/src/pages/Index.tsx b/client/src/pages/Index.tsx index f9b842c..846003c 100644 --- a/client/src/pages/Index.tsx +++ b/client/src/pages/Index.tsx @@ -12,7 +12,6 @@ const Index: FC = () => { const createGame = async () => { const postGameResponse: AxiosResponse = await axios.post(`/games`) const game = postGameResponse.data - localStorage.setItem(`poule-poule-${game.id}`, game.hostId) navigate(`/lobby/${game.id}`) } diff --git a/client/src/pages/Lobby/Lobby.scss b/client/src/pages/Lobby/Lobby.scss index a1f37e4..078d7e2 100644 --- a/client/src/pages/Lobby/Lobby.scss +++ b/client/src/pages/Lobby/Lobby.scss @@ -4,7 +4,7 @@ $background-color: #f8de96; .Players { margin-top: 1rem; display: flex; - justify-content: space-evenly; + justify-content: flex-start; flex-wrap: wrap; .Player { display: flex; diff --git a/client/src/pages/Lobby/Lobby.tsx b/client/src/pages/Lobby/Lobby.tsx index 14e6da6..c681570 100644 --- a/client/src/pages/Lobby/Lobby.tsx +++ b/client/src/pages/Lobby/Lobby.tsx @@ -22,8 +22,7 @@ const Lobby: FC = (props: LobbyProps) => { const getGameResponse: AxiosResponse = await axios.get( `/games/${props.id}` ) - const game = getGameResponse.data - return game + return getGameResponse.data } const onLoad = async () => { var game = await loadGame() @@ -44,21 +43,23 @@ const Lobby: FC = (props: LobbyProps) => { onLoad() }, [props.id]) + // The oldest member of the lobby is the host + const isGameHost = (game: Game, playerId: string | undefined) => { + return game.players && game.players[0].id === playerId + } + return (
{game && ( <>

Details de la partie ({game.id})

{`Créé ${moment.utc(game.creationDate).fromNow()}`}

-

Statut {game.status}

-

-

Joueurs

{game.players.map(player => ( ))}
diff --git a/client/src/utils/signalrConnector.ts b/client/src/utils/signalrConnector.ts index 6ef56cc..c029955 100644 --- a/client/src/utils/signalrConnector.ts +++ b/client/src/utils/signalrConnector.ts @@ -13,11 +13,6 @@ const connectToGameHub = ( .configureLogging(SignalR.LogLevel.Debug) .build() - // connection - // .start() - // .then(() => onStart && onStart()) - // .catch(err => console.log(err)) - return connection } diff --git a/server/DTO/GameDTOs.cs b/server/DTO/GameDTOs.cs index 6679aeb..431e5b5 100644 --- a/server/DTO/GameDTOs.cs +++ b/server/DTO/GameDTOs.cs @@ -19,7 +19,7 @@ public GameDTO(Game game) hostId = game.HostId; status = game.Status.ToString(); creationDate = game.CreationDate.ToString("o", CultureInfo.InvariantCulture); - players = game.Players.Select(p => new PlayerDTO(p)).ToArray(); + players = game.Players.OrderBy(p => p.CreationDate).Select(player => new PlayerDTO(player)).ToArray(); } public int id { get; set; } public string hostId { get; set; }