From 510c4cfeb666ab385e7200e1ac243fc6ed31043b Mon Sep 17 00:00:00 2001
From: Joffrey BION <joffrey.bion@gmail.com>
Date: Tue, 12 Jun 2018 00:36:08 +0200
Subject: Place current player always at the bottom

---
 frontend/src/components/lobby/RadialPlayerList.jsx | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

(limited to 'frontend/src/components/lobby/RadialPlayerList.jsx')

diff --git a/frontend/src/components/lobby/RadialPlayerList.jsx b/frontend/src/components/lobby/RadialPlayerList.jsx
index c3dd988e..0a148c78 100644
--- a/frontend/src/components/lobby/RadialPlayerList.jsx
+++ b/frontend/src/components/lobby/RadialPlayerList.jsx
@@ -21,7 +21,7 @@ const PlayerItem = ({player, isOwner, isUser}) => (
 );
 
 const PlayerPlaceholder = () => (
-  <Flex column align='center' style={{opacity: 0.4}}>
+  <Flex column align='center' style={{opacity: 0.3}}>
     <UserIcon isOwner={false} isUser={false}/>
     <h5 style={{margin: 0}}>?</h5>
   </Flex>
@@ -35,12 +35,13 @@ const UserIcon = ({isUser, isOwner}) => {
 };
 
 export const RadialPlayerList = ({players, owner, currentPlayer}: RadialPlayerListProps) => {
-  const playerItems = players.map(player => <PlayerItem key={player.username}
-                                                        player={player}
-                                                        isOwner={player.username === owner}
-                                                        isUser={player.username === currentPlayer.username}/>);
+  const orderedPlayers = placeFirst(players.toArray(), currentPlayer.username);
+  const playerItems = orderedPlayers.map(player => <PlayerItem key={player.username}
+                                                               player={player}
+                                                               isOwner={player.username === owner}
+                                                               isUser={player.username === currentPlayer.username}/>);
   const tableImg = <img src={roundTable} alt='Round table' style={{width: 200, height: 200}}/>;
-  return <RadialList items={completeWithPlaceholders(playerItems.toArray())}
+  return <RadialList items={completeWithPlaceholders(playerItems)}
                      centerElement={tableImg}
                      diameter={350}
                      offsetDegrees={180}
@@ -48,6 +49,13 @@ export const RadialPlayerList = ({players, owner, currentPlayer}: RadialPlayerLi
                      itemHeight={100}/>;
 };
 
+function placeFirst(players: Array<Player>, targetFirstUsername: string): Array<Player> {
+  while (players[0].username !== targetFirstUsername) {
+    players.push(players.shift());
+  }
+  return players;
+}
+
 function completeWithPlaceholders(playerItems: Array<React.Node>): Array<React.Node> {
   while (playerItems.length < 3) {
     playerItems.push(<PlayerPlaceholder/>);
-- 
cgit 

