cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              body
  background: #457E86
h1
  font-family: cursive
  display: flex
  justify-content: center
  font-size: 3em
  margin: 10px

h1 img
  max-width: 400px

table
  border-spacing: 0
  font-family: sans-serif
  display: flex
  justify-content: center
  
/* row striping */
tr:nth-of-type(odd)
  background: #eee
tr:nth-of-type(even)
  background: white

th
  background: #381F0B
  color: white
  font-weight: bold

th a
  color: white

th a.active.asc:after
  content: " \25bc"
  
th a.active.desc:after
  content: " \25b2"
  
a
  text-decoration: none
  
a:hover
  text-decoration: underline
  
td, th
  padding: 1em
  border: none
  text-align: left
  font-size: 1em

.camperName img
  height: 2em
  border-radius: 5px
  vertical-align: middle

td a:last-child
  color: black
  margin-left: 10px
  
td:nth-of-type(1), td:nth-of-type(3), td:nth-of-type(4)
  text-align: center

  
  
            
          
!
            
              /** USER STORIES **
User Story: I can see a table of the Free Code Camp campers who've earned the most brownie points in the past 30 days.
User Story: I can see how many brownie points they've earned in the past 30 days, and how many they've earned total.
User Story: I can toggle between sorting the list by how many bronwie points they've earned in the past 30 days and by how many brownie points they've earned total.
Hint: To get the top 100 campers for the last 30 days: https://fcctop100.herokuapp.com/api/fccusers/top/recent.
Hint: To get the top 100 campers of all time: https://fcctop100.herokuapp.com/api/fccusers/top/alltime.
**/

var CamperTable = React.createClass({
  render: function() {
    var dataNodes = this.props.data.map(function(data) {
      var userUrl = 'https://www.freecodecamp.com/'+data.username;
      return (
        <tr>
          <td className="camperId">
            {data.id}
          </td>
          <td className="camperName">
            <a href={userUrl} target="_blank"><img src={data.img}/></a>
            <a href={userUrl} target="_blank">{data.username}</a>
          </td>
          <td className="points30Days">
            {data.recent}
          </td>
          <td className="pointsAllTime">
            {data.alltime}
          </td>
        </tr>
      );
    });

    return (
      <tbody>
        {dataNodes}
      </tbody>
    );
  }
});

var LeaderBoard = React.createClass({
  getInitialState: function() {
    return {data: []};
  },
  componentDidMount: function(url) {
    if (!url) {
      var url = this.props.url;
    }
    $.ajax({
      url: url,
      dataType: 'json',
      cache: false,
      success: function(data) {
        for (var i=0;i<data.length;i++) {
          data[i].id = i+1;
        }
        this.setState({data: data});
      }.bind(this),
      error: function(xhr, status, err) {
        console.error(this.props.url, status, err.toString());
      }.bind(this)
    });
  },
  updateTable: function(event) {
    // Re-sort existing dataset
    if (event.target.classList[0] =='active') {
      var data = this.state.data.reverse();
      this.setState({data: data});
      $('.active').toggleClass('asc desc');
    } else {
    // Fetch new data from the API if new dataset chosen
      this.componentDidMount('https://fcctop100.herokuapp.com/api/fccusers/top/'+event.target.id)
      $('#recent').toggleClass('active');
      $('#alltime').toggleClass('active');
      $('#'+event.target.id).removeClass('desc asc').addClass('asc');
    }
  },
  render: function() {
    return (
      <div className="leaderBoard">
        <h1><img src="https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg" alt="Free Code Camp"></img></h1>
        <div className="camperTable">
          <table>
            <thead><tr>
              <th>#</th>
              <th>Camper</th>
              <th><a href="#" id="recent" className="active asc" onClick={this.updateTable}>Recent points</a></th>
              <th><a href="#" id="alltime" className="" onClick={this.updateTable}>Total points</a></th>
            </tr></thead>
            <CamperTable data={this.state.data}/>
          </table>
        </div>
      </div>
    );
  }
});

React.render(<LeaderBoard url='https://fcctop100.herokuapp.com/api/fccusers/top/recent'/>, document.getElementById('container'));
            
          
!
999px
Loading ..................

Console