FCC Challenge: Camper Leaderboard

In this example below you will see how to do a FCC Challenge: Camper Leaderboard with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by Fcmam5, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Fcmam5 ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>FCC Challenge: Camper Leaderboard</title>
  
  
  <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css'>

      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id="root"></div>
  <script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.30.7/react-bootstrap.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/Fcmam5/fcc-challenge-camper-leaderboard-GrdLqX */
body {
  margin: 0;
  padding: 0;
}

.main-list {
  margin: 20px;
}

th a {
  color: #000;
  text-decoration: underline;
}


/*Downloaded from https://www.codeseek.co/Fcmam5/fcc-challenge-camper-leaderboard-GrdLqX */
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Table = ReactBootstrap.Table;

var Board = function (_React$Component) {
  _inherits(Board, _React$Component);

  function Board() {
    _classCallCheck(this, Board);

    return _possibleConstructorReturn(this, (Board.__proto__ || Object.getPrototypeOf(Board)).apply(this, arguments));
  }

  _createClass(Board, [{
    key: "render",
    value: function render() {
      return React.createElement(CampersList, null);
    }
  }]);

  return Board;
}(React.Component);

var CampersList = function (_React$Component2) {
  _inherits(CampersList, _React$Component2);

  function CampersList() {
    _classCallCheck(this, CampersList);

    var _this2 = _possibleConstructorReturn(this, (CampersList.__proto__ || Object.getPrototypeOf(CampersList)).call(this));

    _this2.state = { campers: [] };
    return _this2;
  }

  _createClass(CampersList, [{
    key: "getRecent",
    value: function getRecent() {
      var _this3 = this;

      fetch("https://fcctop100.herokuapp.com/api/fccusers/top/recent").then(function (resp) {
        return resp.json();
      }).then(function (data) {
        return _this3.setState({ campers: data });
      }).catch(function (err) {
        return console.error(err);
      });
    }
  }, {
    key: "getAllTime",
    value: function getAllTime() {
      var _this4 = this;

      fetch("https://fcctop100.herokuapp.com/api/fccusers/top/alltime").then(function (resp) {
        return resp.json();
      }).then(function (data) {
        return _this4.setState({ campers: data });
      }).catch(function (err) {
        return console.error(err);
      });
    }
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      this.getAllTime();
    }
  }, {
    key: "render",
    value: function render() {
      return React.createElement(
        "div",
        { className: "main-list" },
        React.createElement(
          Table,
          { striped: true, bordered: true, condensed: true, hover: true },
          React.createElement(
            "thead",
            null,
            React.createElement(
              "tr",
              null,
              React.createElement(
                "th",
                null,
                "Username"
              ),
              React.createElement(
                "th",
                null,
                React.createElement(
                  "a",
                  { href: "#", onClick: this.getAllTime.bind(this) },
                  "Alltime"
                )
              ),
              React.createElement(
                "th",
                null,
                React.createElement(
                  "a",
                  { href: "#", onClick: this.getRecent.bind(this) },
                  "Recent"
                )
              )
            )
          ),
          React.createElement(CamperItem, { theCampers: this.state.campers })
        )
      );
    }
  }]);

  return CampersList;
}(React.Component);

var CamperItem = function (_React$Component3) {
  _inherits(CamperItem, _React$Component3);

  function CamperItem() {
    _classCallCheck(this, CamperItem);

    return _possibleConstructorReturn(this, (CamperItem.__proto__ || Object.getPrototypeOf(CamperItem)).apply(this, arguments));
  }

  _createClass(CamperItem, [{
    key: "render",
    value: function render() {
      var rows = this.props.theCampers.map(function (m) {
        var name = m.username;
        return React.createElement(
          "tr",
          null,
          React.createElement(
            "td",
            null,
            React.createElement(
              "a",
              { href: "https://www.freecodecamp.com/" + name },
              React.createElement("img", { src: m.img, width: "30", alt: name + " avatar" }),
              " ",
              name
            )
          ),
          React.createElement(
            "td",
            null,
            m.alltime
          ),
          React.createElement(
            "td",
            null,
            m.recent
          )
        );
      });

      return React.createElement(
        "tbody",
        null,
        rows
      );
    }
  }]);

  return CamperItem;
}(React.Component);

ReactDOM.render(React.createElement(Board, null), document.getElementById('root'));

Comments