Skip to content

Commit

Permalink
Change host assignment
Browse files Browse the repository at this point in the history
The host is now the oldest member of the lobby
  • Loading branch information
ThunderDev1 committed Dec 4, 2019
1 parent 102a9f8 commit c05083e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions client/src/components/PlayerBox/PlayerBox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ $background-color: rgb(37, 153, 138);
background-color: $background-color;
color: white;
padding: 1rem;
margin: 1rem;
min-width: 10rem;
}
1 change: 0 additions & 1 deletion client/src/pages/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const Index: FC<IndexProps> = () => {
const createGame = async () => {
const postGameResponse: AxiosResponse<Game> = await axios.post(`/games`)
const game = postGameResponse.data
localStorage.setItem(`poule-poule-${game.id}`, game.hostId)
navigate(`/lobby/${game.id}`)
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Lobby/Lobby.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions client/src/pages/Lobby/Lobby.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const Lobby: FC<LobbyProps> = (props: LobbyProps) => {
const getGameResponse: AxiosResponse<Game> = await axios.get(
`/games/${props.id}`
)
const game = getGameResponse.data
return game
return getGameResponse.data
}
const onLoad = async () => {
var game = await loadGame()
Expand All @@ -44,21 +43,23 @@ const Lobby: FC<LobbyProps> = (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 (
<div className='Lobby'>
{game && (
<>
<h1>Details de la partie ({game.id})</h1>
<h2>{`Créé ${moment.utc(game.creationDate).fromNow()}`}</h2>
<h3>Statut {game.status}</h3>
<br></br>
<h4>Joueurs</h4>
<div className='Players'>
{game.players.map(player => (
<PlayerBox
name={player.name}
isSelf={currentPlayerId === player.id || false}
isHost={game.hostId === player.id}
isHost={isGameHost(game, player.id)}
/>
))}
</div>
Expand Down
5 changes: 0 additions & 5 deletions client/src/utils/signalrConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ const connectToGameHub = (
.configureLogging(SignalR.LogLevel.Debug)
.build()

// connection
// .start()
// .then(() => onStart && onStart())
// .catch(err => console.log(err))

return connection
}

Expand Down
2 changes: 1 addition & 1 deletion server/DTO/GameDTOs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit c05083e

Please sign in to comment.