Results.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from "react";
  2. import { Link } from "react-router";
  3. import styles from "../styles";
  4. import Loading from "../components/Loading";
  5. import MainContainer from "../containers/MainContainer";
  6. import UserDetails from "../components/UserDetails";
  7. import UserDetailsWrapper from "../components/UserDetailsWrapper";
  8. const PropTypes = React.PropTypes;
  9. const StartOver = () => {
  10. return (
  11. <div className="col-sm-12" style={styles.space}>
  12. <Link to="/playerOne">
  13. <button type="button" className="btn btn-lg btn-danger">Start over</button>
  14. </Link>
  15. </div>
  16. );
  17. };
  18. const Results = (props) => {
  19. if (props.isLoading === true) {
  20. return <Loading text="One moment" speed={50} />;
  21. }
  22. if (props.scores[0] === props.scores[1]) {
  23. return (
  24. <MainContainer>
  25. <h1>It's a tie</h1>
  26. <StartOver path="/playerOne" />
  27. </MainContainer>
  28. );
  29. }
  30. const winningIndex = props.scores[0] > props.scores[1] ? 0 : 1;
  31. const losingIndex = winningIndex ? 0 : 1;
  32. return (
  33. <MainContainer>
  34. <h1>Results</h1>
  35. <div className="col-sm-8 col-sm-offset-2">
  36. <UserDetailsWrapper header="Winner">
  37. <UserDetails score={props.scores[winningIndex]} info={props.playerInfo[winningIndex]} />
  38. </UserDetailsWrapper>
  39. <UserDetailsWrapper header="Loser">
  40. <UserDetails score={props.scores[losingIndex]} info={props.playerInfo[losingIndex]} />
  41. </UserDetailsWrapper>
  42. </div>
  43. <StartOver />
  44. </MainContainer>
  45. );
  46. };
  47. Results.propTypes = {
  48. isLoading: PropTypes.bool.isRequired,
  49. playerInfo: PropTypes.array.isRequired,
  50. scores: PropTypes.array.isRequired
  51. };
  52. export default Results;