浏览代码

Some further refactoring of pre game into sub components

Kirk Trombley 5 年之前
父节点
当前提交
96933723db
共有 1 个文件被更改,包括 28 次插入18 次删除
  1. 28 18
      ui/src/components/pre-game.component.jsx

+ 28 - 18
ui/src/components/pre-game.component.jsx

@@ -10,32 +10,40 @@ const initialState = playerName => ({
   playerName,
   playerName,
 });
 });
 
 
-const NewGame = ({ playerName, onChangePlayerName, onCreateGame, cannotCreateGame }) => (
-  <div>
-    <p>Player Name</p>
-    <input type="text" value={playerName} onChange={onChangePlayerName} />
-    <hr/>
-    <button onClick={onCreateGame} disabled={cannotCreateGame}>
-      Create New Game
-    </button>
+const PlayerName = ({ playerName, onChangePlayerName }) => (
+  <div style={{
+    display: "flex",
+    flexFlow: "column nowrap",
+    justifyContent: "center",
+    alignItems: "center",
+  }}>
+    <span style={{ padding: "0.2em" }}>Player Name</span>
+    <input style={{ padding: "0.1em" }} type="text" value={playerName} onChange={onChangePlayerName} />
   </div>
   </div>
 );
 );
 
 
+const NewGame = ({ onCreateGame, cannotCreateGame }) => (
+  <button onClick={onCreateGame} disabled={cannotCreateGame}>
+    Create New Game
+  </button>
+);
+
 const JoinGame = ({ gameId, onChangeGameId, onJoinGame, cannotJoinGame }) => (
 const JoinGame = ({ gameId, onChangeGameId, onJoinGame, cannotJoinGame }) => (
-  <div>
-    <p>Game ID:</p>
-    <input type="text" value={gameId} onChange={onChangeGameId} />
-    <br/>
-    <button onClick={onJoinGame} disabled={cannotJoinGame}>
+  <div style={{
+    display: "flex",
+    flexFlow: "column nowrap",
+    justifyContent: "center",
+    alignItems: "center",
+  }}>
+    <span style={{ padding: "0.1em" }}>Game ID:</span>
+    <input style={{ margin: "0.1em" }} type="text" value={gameId} onChange={onChangeGameId} />
+    <button style={{ margin: "0.1em" }} onClick={onJoinGame} disabled={cannotJoinGame}>
       Join Existing Game
       Join Existing Game
     </button>
     </button>
   </div>
   </div>
 );
 );
 
 
-const PreGame = ({
-  initPlayerName,
-  onGameJoined
-}) => {
+const PreGame = ({ initPlayerName, onGameJoined }) => {
   const [state, setState] = useState(initialState(initPlayerName));
   const [state, setState] = useState(initialState(initPlayerName));
   const { loading, gameId, playerName } = state;
   const { loading, gameId, playerName } = state;
 
 
@@ -61,7 +69,9 @@ const PreGame = ({
 
 
   return (
   return (
     <div>
     <div>
-      <NewGame {...{ playerName, onChangePlayerName, onCreateGame, cannotCreateGame }} />
+      <PlayerName {...{ playerName, onChangePlayerName }} />
+      <hr/>
+      <NewGame {...{ onCreateGame, cannotCreateGame }} />
       <hr/>
       <hr/>
       <JoinGame {...{ gameId, onChangeGameId, onJoinGame, cannotJoinGame }} />
       <JoinGame {...{ gameId, onChangeGameId, onJoinGame, cannotJoinGame }} />
     </div>
     </div>