|
@@ -2,11 +2,7 @@ import React, { useState } from "react";
|
|
|
import styled from "styled-components";
|
|
|
import Button from "../../util/Button";
|
|
|
import Loading from "../../util/Loading";
|
|
|
-import { dispatch, useGameId, usePlayerName } from "../../../domain/gameStore";
|
|
|
-
|
|
|
-const Label = styled.span`
|
|
|
- padding: 0.2em;
|
|
|
-`
|
|
|
+import { dispatch, usePlayerName } from "../../../domain/gameStore";
|
|
|
|
|
|
const FormInput = styled.input`
|
|
|
border-radius: 0px;
|
|
@@ -14,16 +10,20 @@ const FormInput = styled.input`
|
|
|
background-color: #181a1b;
|
|
|
color: #eee;
|
|
|
padding: 0.5em;
|
|
|
+ margin-left: 2em;
|
|
|
+ margin-right: 2em;
|
|
|
+ height: 100%;
|
|
|
`
|
|
|
|
|
|
-const FormButton = styled(Button)`
|
|
|
- padding: 1em;
|
|
|
- margin: 0.2em;
|
|
|
- margin-top: 0.3em;
|
|
|
+const NameInputGroup = styled.div`
|
|
|
+ display: flex;
|
|
|
+ flex-flow: row nowrap;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+ margin-bottom: 1em;
|
|
|
`
|
|
|
|
|
|
const JoinForm = () => {
|
|
|
- const gameId = useGameId();
|
|
|
const playerName = usePlayerName();
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [failed, setFailed] = useState(false);
|
|
@@ -49,16 +49,17 @@ const JoinForm = () => {
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
- {failed && <Label>Failed to join the game! Maybe try a different name?</Label>}
|
|
|
- <Label>Joining {gameId}...</Label>
|
|
|
- <Label>Player Name</Label>
|
|
|
- <FormInput
|
|
|
- type="text"
|
|
|
- value={playerName || ""}
|
|
|
- onChange={({ target }) => dispatch.setPlayerName(target.value)}
|
|
|
- onKeyDown={({ key }) => { if (key === "Enter") { onJoinGame() }}}
|
|
|
- />
|
|
|
- <FormButton onClick={onJoinGame} disabled={cannotJoinGame}>Join Game</FormButton>
|
|
|
+ {failed && "Failed to join the game! Maybe try a different name?"}
|
|
|
+ <NameInputGroup>
|
|
|
+ Enter your name to join:
|
|
|
+ <FormInput
|
|
|
+ type="text"
|
|
|
+ value={playerName || ""}
|
|
|
+ onChange={({ target }) => dispatch.setPlayerName(target.value)}
|
|
|
+ onKeyDown={({ key }) => { if (key === "Enter") { onJoinGame() }}}
|
|
|
+ />
|
|
|
+ <Button onClick={onJoinGame} disabled={cannotJoinGame}>Join Game</Button>
|
|
|
+ </NameInputGroup>
|
|
|
</>
|
|
|
);
|
|
|
};
|