Lobby.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from "react";
  2. import "./css/lobby.css"
  3. import Colors from "./util/colors";
  4. import deck from './img/deck.svg';
  5. import { SiteState } from "./StateRouter";
  6. export default function Lobby({ message, pickColor, deal }) {
  7. const { color, options, state: { code: state, args: { game_code, ...state_args } } } = message;
  8. const freeColors = (options && options.map((o) => o.color)) || [];
  9. const circle_args = { state, myColor: color, freeColors, pickColor };
  10. return <div className="mt-4">
  11. {
  12. state === SiteState.JOIN_OTHERS &&
  13. <div className="row my-2">
  14. <h1>Je kan meedoen door naar <a href={`/${game_code}`}>{window.location.host}/{game_code}</a> te gaan
  15. </h1>
  16. </div>
  17. }{/*<hr/>*/}{
  18. state !== SiteState.JOIN_OTHERS &&
  19. <div className="row justify-content-center my-2">
  20. <Circle color={Colors.RED} {...circle_args}/>
  21. <Circle color={Colors.YELLOW} {...circle_args}/>
  22. <Circle color={Colors.BLUE} {...circle_args}/>
  23. <Circle color={Colors.GREEN} {...circle_args}/>
  24. </div>
  25. }{
  26. state === SiteState.FIRST_DEAL &&
  27. <div className="row justify-content-center my-2">
  28. <div className="btn btn-link" onClick={deal}>
  29. <img src={deck} alt="kaartenstapel"/>
  30. <br/>
  31. <span>Delen</span>
  32. </div>
  33. </div>
  34. }
  35. </div>
  36. }
  37. function Circle({ state, color, myColor, freeColors, pickColor }) {
  38. const isMine = color === myColor;
  39. const isSelectable = freeColors.includes(color)
  40. const isPicked = state === SiteState.PICK_COLOR && !isSelectable;
  41. return <div className="col-2">
  42. <div className={`color-pick ${color} ${isPicked ? "selected" : ""} ${isSelectable ? "selectable" : ""} ${isMine ? "mine" : ""}`}
  43. onClick={() => isSelectable && pickColor(color)}
  44. />
  45. </div>
  46. }