cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              $size: 16px

body 
  font-family: sans-serif

h1
  font-size: $size*2
  text-align: center
  font-weight: 700
  padding-top: 20px
  padding-bottom: 20px

p
  padding: 20px
  text-align: center
  
table
  margin-left: auto
  margin-right: auto
  
td, th 
  padding: 10px
  vertical-align: middle
  font-size: $size
  
  img
    width: 60px
    height: 60px
    
.row 
  border: 1px solid #999
  color: #333
  
.evenRow
  @extend .row
  background-color: #999

.oddRow
  @extend .row
  background-color: white
 
.selected 
  font-weight: 700
  color: gray
  text-decoration: underline
  cursor: pointer

.unselected
  font-weight: 400
  color: black
  text-decoration: underline
  cursor: pointer

#loading
  width: 2*$size
  margin: 50px 0 50px 0
  font-size: 30px
  text-align: center
            
          
!
            
              class App extends React.Component {
  render() {
    return <div>
      <h1>FreeCodeCamp Leaderboard</h1>
      <LeaderBoard />
      <p>Code by <a href="http://lukewalker.org" target="_blank">Luke Walker</a></p>
    </div>
  }                                          
}

class UserRow extends React.Component {
  render() {
    var rank = this.props.index + 1;
    var rowStyle = rank % 2 === 0 ? 'evenRow' : 'oddRow'
    return <tr className={rowStyle} key={rank}><td>{rank}</td><td><img src={this.props.avatar} /></td><td>{this.props.username}</td><td>{this.props.recent}</td><td>{this.props.alltime}</td></tr>;
  }  
}

class LeaderBoard extends React.Component {
  constructor(props) {
    super(props)
    this.state = { users: [], sort: 'Recent', loading: true } 
    this.recent = this.recent.bind(this)
    this.alltime = this.alltime.bind(this)
  }
  componentDidMount() {
    this.recent()
  }
  renderLoading() {
    return <div id="loading">Loading...</div>
  }
  recent() {
    $.get(recent)
    .then(data => this.setState({ users: data, sort: 'Recent', loading: false }))
  }
  alltime() {
    $.get(alltime)
    .then(data => this.setState({ users: data, sort: 'All Time', loading: false }))
  }
  render() {
    var leaderList = this.state.users.map((user, idx) => <UserRow index={idx} avatar={user.img} username={user.username} recent={user.recent} alltime={user.alltime} /> )
    return <table>
      <thead><tr><th>Rank</th><th>Avatar</th><th>Username</th><th onClick={this.recent} className={this.state.sort === 'Recent' ? 'selected' : 'unselected'}>Recent</th><th onClick={this.alltime} className={this.state.sort === 'All Time' ? 'selected' : 'unselected'}>All Time</th></tr></thead>
      <tbody>{ this.state.loading? this.renderLoading() : leaderList }</tbody></table>
  }
}


var recent = "https://fcctop100.herokuapp.com/api/fccusers/top/recent"
var alltime = "https://fcctop100.herokuapp.com/api/fccusers/top/alltime"        
ReactDOM.render(<App />, document.querySelector('#app'))
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console