|
@@ -6,6 +6,7 @@ import Loading from "../../util/Loading";
|
|
|
import PlayerNameInput from "../../util/PlayerNameInput";
|
|
|
import LobbyPlayerList from "./LobbyPlayerList";
|
|
|
import { joinGame } from "../../../domain/GGSHService";
|
|
|
+import useCountdown from "../../util/Timer/useCountdown";
|
|
|
|
|
|
const InfoContainer = styled.div`
|
|
|
flex: 3;
|
|
@@ -41,14 +42,34 @@ const getUrl = gameId => {
|
|
|
return u.href;
|
|
|
}
|
|
|
|
|
|
-const LobbyInfo = ({ gameId, playerName, onStart }) => (
|
|
|
- <InfoContainer>
|
|
|
- <Label>Playing as {playerName}</Label>
|
|
|
- <Label>Use this link to invite other players:</Label>
|
|
|
- <Label><ClickToCopy text={getUrl(gameId)} /></Label>
|
|
|
- <FormButton onClick={onStart}>Start Game</FormButton>
|
|
|
- </InfoContainer>
|
|
|
-);
|
|
|
+const CountdownButton = ({ onCancelled, onEnd }) => {
|
|
|
+ const [remaining, pause] = useCountdown(5, onEnd);
|
|
|
+ return (
|
|
|
+ <FormButton onClick={() => { pause(); onCancelled(); }}>
|
|
|
+ {remaining !== 0 ? JSON.stringify(remaining) : "Starting!"}
|
|
|
+ </FormButton>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const LobbyInfo = ({ gameId, playerName, onStart }) => {
|
|
|
+ const [delayed, setDelayed] = useState(false);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <InfoContainer>
|
|
|
+ <Label>Playing as {playerName}</Label>
|
|
|
+ <Label>Use this link to invite other players:</Label>
|
|
|
+ <Label><ClickToCopy text={getUrl(gameId)} /></Label>
|
|
|
+ {
|
|
|
+ delayed
|
|
|
+ ? <CountdownButton
|
|
|
+ onCancelled={() => setDelayed(false)}
|
|
|
+ onEnd={() => { setDelayed(false); onStart(); }}
|
|
|
+ />
|
|
|
+ : <FormButton onClick={() => setDelayed(true)}>Start Game</FormButton>
|
|
|
+ }
|
|
|
+ </InfoContainer>
|
|
|
+ )
|
|
|
+};
|
|
|
|
|
|
const JoinForm = ({ gameId, onGameJoined }) => {
|
|
|
const [loading, setLoading] = useState(false);
|