|
@@ -1,24 +1,44 @@
|
|
|
-import React from "react";
|
|
|
|
|
|
|
+import React, { Fragment, useRef } from "react";
|
|
|
import "./css/lobby.css"
|
|
import "./css/lobby.css"
|
|
|
import Colors from "./util/colors";
|
|
import Colors from "./util/colors";
|
|
|
import deck from './img/deck.svg';
|
|
import deck from './img/deck.svg';
|
|
|
import { Commands } from "./StateRouter";
|
|
import { Commands } from "./StateRouter";
|
|
|
|
|
|
|
|
-export default function Lobby({ message, pickColor, deal }) {
|
|
|
|
|
- const { color, options, state, game_code, others, name,...args } = message;
|
|
|
|
|
|
|
+export default function Lobby({ message, pickColor, deal, setName }) {
|
|
|
|
|
+ const { color, options, state, game_code, others, name, ...args } = message;
|
|
|
const pickableColors = options.filter((o) => o.code === Commands.PICK_COLOR).map((o) => o.color);
|
|
const pickableColors = options.filter((o) => o.code === Commands.PICK_COLOR).map((o) => o.color);
|
|
|
- const circle_args = { state, myColor: color, myName: name, others, pickableColors, pickColor };
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const timeoutCode = useRef(null);
|
|
|
|
|
+
|
|
|
|
|
+ const scheduleSetName = (name) => {
|
|
|
|
|
+ if (timeoutCode.current !== null) {
|
|
|
|
|
+ window.clearTimeout(timeoutCode.current);
|
|
|
|
|
+ }
|
|
|
|
|
+ timeoutCode.current = window.setTimeout(() => {
|
|
|
|
|
+ timeoutCode.current = null;
|
|
|
|
|
+ setName(name);
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const circle_args = { state, myColor: color, myName: name, setMyName: scheduleSetName, others, pickableColors, pickColor };
|
|
|
const canDeal = options.find((o) => o.code === Commands.DEAL);
|
|
const canDeal = options.find((o) => o.code === Commands.DEAL);
|
|
|
- return <div className="mt-4">
|
|
|
|
|
- <div className="row my-2">
|
|
|
|
|
- <h1>Je kan meedoen door naar <a href={`/${game_code}`}>{window.location.host}/{game_code}</a> te gaan
|
|
|
|
|
- </h1>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return <Fragment>
|
|
|
|
|
+ <div className="top-bar">
|
|
|
|
|
+ <span>Je kan meedoen door naar <a
|
|
|
|
|
+ href={`/${game_code}`}>{window.location.origin}/{game_code}</a> te gaan</span>
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="row justify-content-center my-2">
|
|
|
|
|
- <Circle color={Colors.RED} {...circle_args}/>
|
|
|
|
|
- <Circle color={Colors.YELLOW} {...circle_args}/>
|
|
|
|
|
- <Circle color={Colors.BLUE} {...circle_args}/>
|
|
|
|
|
- <Circle color={Colors.GREEN} {...circle_args}/>
|
|
|
|
|
|
|
+ <div className="content">
|
|
|
|
|
+ <div className="container">
|
|
|
|
|
+ <div className="row justify-content-center my-2">
|
|
|
|
|
+ <Pawn color={Colors.RED} {...circle_args}/>
|
|
|
|
|
+ <Pawn color={Colors.BLUE} {...circle_args}/>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="row justify-content-center my2">
|
|
|
|
|
+ <Pawn color={Colors.YELLOW} {...circle_args}/>
|
|
|
|
|
+ <Pawn color={Colors.GREEN} {...circle_args}/>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
{
|
|
{
|
|
|
canDeal &&
|
|
canDeal &&
|
|
@@ -30,24 +50,35 @@ export default function Lobby({ message, pickColor, deal }) {
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
}
|
|
}
|
|
|
- </div>
|
|
|
|
|
|
|
+ </Fragment>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function Circle({ color, myColor, myName, others, pickableColors, pickColor }) {
|
|
|
|
|
|
|
+function Pawn({ color, myColor, myName, setMyName, others, pickableColors, pickColor }) {
|
|
|
const isMine = color === myColor;
|
|
const isMine = color === myColor;
|
|
|
const playerInfo = isMine ?
|
|
const playerInfo = isMine ?
|
|
|
- {color, name: myName} :
|
|
|
|
|
|
|
+ { color, name: myName } :
|
|
|
others.find((o) => o.color === color);
|
|
others.find((o) => o.color === color);
|
|
|
const isSelectable = pickableColors.includes(color);
|
|
const isSelectable = pickableColors.includes(color);
|
|
|
const isPicked = !isSelectable;
|
|
const isPicked = !isSelectable;
|
|
|
- const name = (playerInfo && playerInfo.name) || "";
|
|
|
|
|
- return <div className="col-2 flex-column">
|
|
|
|
|
|
|
+ const name = (playerInfo && playerInfo.name) || "\u00a0";
|
|
|
|
|
+ return <div className="col col-lg-3 col-md-4">
|
|
|
<div className={`color-pick
|
|
<div className={`color-pick
|
|
|
${color} ${isPicked ? "selected" : ""}
|
|
${color} ${isPicked ? "selected" : ""}
|
|
|
${isSelectable ? "selectable" : ""}
|
|
${isSelectable ? "selectable" : ""}
|
|
|
${isMine ? "mine" : ""}`}
|
|
${isMine ? "mine" : ""}`}
|
|
|
- onClick={() => isSelectable && pickColor(color)}
|
|
|
|
|
- />
|
|
|
|
|
- <h4>{name}</h4>
|
|
|
|
|
|
|
+ onClick={() => isSelectable && pickColor(color)}>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {isMine ?
|
|
|
|
|
+ <form className="color-pick-name">
|
|
|
|
|
+ <input className="form-control"
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ defaultValue={myName}
|
|
|
|
|
+ placeholder="Naam"
|
|
|
|
|
+ onChange={(e) => {
|
|
|
|
|
+ e.preventDefault();
|
|
|
|
|
+ setMyName(e.target.value);
|
|
|
|
|
+ }}/>
|
|
|
|
|
+ </form> :
|
|
|
|
|
+ <div className="color-pick-name">{name}</div>}
|
|
|
</div>
|
|
</div>
|
|
|
-}
|
|
|
|
|
|
|
+}
|