|
@@ -1,10 +1,10 @@
|
|
-import React from "react";
|
|
|
|
|
|
+import React, { useState } from "react";
|
|
import styled from "styled-components";
|
|
import styled from "styled-components";
|
|
import ms from "pretty-ms";
|
|
import ms from "pretty-ms";
|
|
import LobbyPlayerList from "./LobbyPlayerList";
|
|
import LobbyPlayerList from "./LobbyPlayerList";
|
|
import HeaderAndFooter from "../../util/HeaderAndFooter";
|
|
import HeaderAndFooter from "../../util/HeaderAndFooter";
|
|
import ClickToCopy from "../../util/ClickToCopy";
|
|
import ClickToCopy from "../../util/ClickToCopy";
|
|
-import { useGameJoined, useGameId } from "../../../domain/gameStore";
|
|
|
|
|
|
+import { useGameId } from "../../../domain/gameStore";
|
|
import JoinForm from "./JoinForm";
|
|
import JoinForm from "./JoinForm";
|
|
import StartGame from "./StartGame";
|
|
import StartGame from "./StartGame";
|
|
import useGameInfo from "../../../hooks/useGameInfo";
|
|
import useGameInfo from "../../../hooks/useGameInfo";
|
|
@@ -21,6 +21,14 @@ const InfoContainer = styled.div`
|
|
height: 100%;
|
|
height: 100%;
|
|
`
|
|
`
|
|
|
|
|
|
|
|
+const FormContainer = styled.div`
|
|
|
|
+ flex: 1;
|
|
|
|
+
|
|
|
|
+ display: flex;
|
|
|
|
+ flex-flow: column nowrap;
|
|
|
|
+ justify-content: center;
|
|
|
|
+`
|
|
|
|
+
|
|
const PageContainer = styled.div`
|
|
const PageContainer = styled.div`
|
|
flex: 1;
|
|
flex: 1;
|
|
display: flex;
|
|
display: flex;
|
|
@@ -42,8 +50,8 @@ const getUrl = gameId => {
|
|
|
|
|
|
const Lobby = ({ onStart }) => {
|
|
const Lobby = ({ onStart }) => {
|
|
const gameId = useGameId();
|
|
const gameId = useGameId();
|
|
- const joined = useGameJoined();
|
|
|
|
const { players, rounds, timer } = useGameInfo();
|
|
const { players, rounds, timer } = useGameInfo();
|
|
|
|
+ const [joined, setJoined] = useState(false);
|
|
|
|
|
|
if (!players || !rounds || !timer) {
|
|
if (!players || !rounds || !timer) {
|
|
return <Loading/>
|
|
return <Loading/>
|
|
@@ -54,11 +62,13 @@ const Lobby = ({ onStart }) => {
|
|
<PageContainer>
|
|
<PageContainer>
|
|
<InfoContainer>
|
|
<InfoContainer>
|
|
<Label>Game will run for {rounds} rounds, each with a {ms(timer * 1000)} time limit</Label>
|
|
<Label>Game will run for {rounds} rounds, each with a {ms(timer * 1000)} time limit</Label>
|
|
- {
|
|
|
|
- joined
|
|
|
|
- ? <StartGame onStart={onStart}/>
|
|
|
|
- : <JoinForm />
|
|
|
|
- }
|
|
|
|
|
|
+ <FormContainer>
|
|
|
|
+ {
|
|
|
|
+ joined
|
|
|
|
+ ? <StartGame onStart={onStart}/>
|
|
|
|
+ : <JoinForm onJoined={() => setJoined(true)}/>
|
|
|
|
+ }
|
|
|
|
+ </FormContainer>
|
|
<Label><ClickToCopy text={getUrl(gameId)}>Click here to copy an invite link!</ClickToCopy></Label>
|
|
<Label><ClickToCopy text={getUrl(gameId)}>Click here to copy an invite link!</ClickToCopy></Label>
|
|
</InfoContainer>
|
|
</InfoContainer>
|
|
<LobbyPlayerList playerNames={players?.map(({ name }) => name) ?? []} />
|
|
<LobbyPlayerList playerNames={players?.map(({ name }) => name) ?? []} />
|