Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id='app'></div>
              
            
!

CSS

              
                /*
Page Settings
*/

$light-gray:rgb(242,242,242);
$dark-gray:rgb(51,51,51);

body {
	font-family:Raleway, sans-serif;
	background:$light-gray;
}


.navbar {
	background:$light-gray;
	margin-bottom:0px;

  .lead {
    font-size:28px;
  }
}

/*
table header
*/
.row-header  {
  &:hover {
      color:$dark-gray;
    }

	.number-header,
	.data-header,
	.user-header {
		outline:none;
    border:none;
		background:rgb(140,210,140);
	}

	.number-header {
	}
	.user-header {
		padding-left:30px;
	}

  .data-header {
    cursor:pointer;
	}

  .fa {
    margin-left:5%;
  }
}

/*
Table Content
*/
tr {

  &:hover {
    color:rgb(238,238,238);

    td {
      transition:background .25s, color .25s;
      background:rgb(85,0,85);
    }
    img {
      width:75px;
      border-radius:50%;
    }
  }

  &:nth-child(even) {
	  background:rgb(182,220,182);
  }

  &:nth-child(odd) {
	  background:rgb(200,220,200);
  }

  td {
    vertical-align:middle !important;
    outline:1px solid rgba(247,247,247,.5);
  }
}

/* User Component */
.user {
  width:100%;

  &_primary {
    width:30%;
  }
  &_image {
    transition:width .25s, border-radius .25s;
    width:50px;
    border-radius:10px;
  }
  &_name {
    padding-left:10px;
  }
}

/*
for hiding footer before ajax data has loaded and for hiding fa-animations
*/
.disabled {
	display:none;
}

/*
On clicking the active data, animation to indicate this data is already active
*/
.animate {
  -webkit-transform: translate(10px) rotate(5deg);
  transform:translate(10px) rotate(5deg);
}

/* Media Queries for Small Screen */
@media screen and (max-width:500px) {
  .navbar .lead {
    font-size:20px;
  }
  .user-header,
  .data-header {
    font-size:14px;
  }
  .user {
    &_name,
    &_number {
      font-size:11px;
    }
    &_score {
      font-size:14px;
    }
    &_image {
      width:40px;
    }
  }
  .container {
    padding:0;
  }
}

              
            
!

JS

              
                var PropTypes = React.PropTypes;

function User (props) {
	return (
      <tr className='align-center disabled user'>
        <td className='h4 text-center user_number'>{props.number}</td>
        <td className='user_primary'>
          <a href={props.url + props.username}
            className='user_link'
            target='blank'
            rel='noopener'>
            <img
              src={props.img}
              className='user_image'
              alt='user image' />
          </a>
          <span
            className='h4 user_name'>
            {props.username}
          </span>
        </td>
        <td>
          <p
            className='h4 text-center user_score'>
            {props.recent}
          </p>
        </td>
        <td>
          <p
            className='h4 text-center user_score'>
            {props.alltime}
          </p>
        </td>
      </tr>
	);
}
User.propTypes = {
  number: PropTypes.number.isRequired,
  url: PropTypes.string.isRequired,
	img: PropTypes.string.isRequired,
	username: PropTypes.string.isRequired,
	recent: PropTypes.number.isRequired,
  allTime: PropTypes.number.isRequired
}

function Footer () {
	return (
		<footer className='footer disabled'>
			<div className='container-fluid'>
				<p className='lead text-center'>
					Made by &nbsp;
					<a href='https://www.freecodecamp.com/robfr77'
						target='_blank'
						rel='noopener'>
						robfr77
					 </a>
				</p>
			</div>
		</footer>
	);
}

function Header () {
  return (
	   <nav className="navbar navbar-default">
  	   <div className="container-fluid">
         <h1 className='lead text-center'>
           <a href='https://www.freecodecamp.com/'
             target='blank'
             rel='noopener'>
             Free Code Camp
           </a>
           &nbsp; Leaderboard
         </h1>
  		  </div>
	   </nav>
  );
}

// The Body component renders the header UI for the table and the User components.
// It also uses the callback functions for loading the data on clicking the top30 or allTime headers
function Body (props) {
	return (
		<div className='table-responsive container'>
		<table className='table table-bordered'>
			<thead>
				<tr className='row-header'>
					<td className='number-header'>
					</td>
					<td
						className='h3 user-header'>
						User
					</td>
					<td
						className='h3 text-center data-header'
						onClick={props.toggleTop30}>
						Last 30
            <i
							id='top30_icon'
							className="fa fa-spinner fa-fw fa-pulse">
            </i>
					</td>
					<td
						className='h3 text-center data-header'
						onClick={props.toggleAllTime}>
						All Time
						<i
							id='allTime_icon'
							className="fa fa-spinner fa-fw fa-pulse disabled">
						</i>
					</td>
				</tr>
			</thead>
			<tbody>
        {props.users.map(function(user) {
          return (
            <User
              key={props.users.indexOf(user)}
              number={props.users.indexOf(user) + 1}
              img={user.img}
              alltime={user.alltime}
              recent={user.recent}
              username={user.username}
              url = 'https://www.freecodecamp.com/'
            />
          );
        })}
			</tbody>
		</table>
		</div>
	);
}
Body.propTypes = {
	users: PropTypes.array.isRequired,
	toggleTop30: PropTypes.func.isRequired,
	toggleAllTime: PropTypes.func.isRequired
}

/* The Body Container passes down the ajax request callbacks & the user data itself to the Body Component. */
/* It is responsible for the animation of the loading state. */
/* It reveals the footer only once the content has loaded. */
var BodyContainer = React.createClass({
	propTypes: {
		onDataToggle:PropTypes.func.isRequired,
		active: PropTypes.string.isRequired,
    top30: PropTypes.array,
    allTime: PropTypes.array
	},
	//callback functions for Body Component
	//check active set of data & animate header if section has already been selected
	//otherwise use callback from App Component to change active data
	toggleTop30: function() {
		if (this.props.active === 'top30') {
      $('#top30_icon').closest('td').toggleClass('animate');
      setTimeout(animateHeader, 100);
      function animateHeader() {
        $('#top30_icon').closest('td').toggleClass('animate');
		  };
    }
		else {
		  this.props.onDataToggle();
		}
	},
	toggleAllTime: function() {
		if (this.props.active === 'allTime') {
		  $('#allTime_icon').closest('td').toggleClass('animate');
      setTimeout(animateHeader, 100);
      function animateHeader() {
        $('#allTime_icon').closest('td').toggleClass('animate');
		  };
		}
		else {
		  this.props.onDataToggle();
	  }
  },
  //toggle pulse animation on component update
  componentWillUpdate: function() {
    function toggleLoadingAnimation() {
      $('.fa-pulse').not('.disabled').toggleClass('disabled');
    }
    toggleLoadingAnimation();
    setTimeout(toggleLoadingAnimation, 500);
  },
  // On Initial Load, reveal the footer only once page content has loaded
  componentDidMount: function() {
    var updatePage = setInterval(revealFooter, 100);
    updatePage();
    function revealFooter() {
      if ($(document).height() > 2000) {
        $('footer').toggleClass('disabled');
        clearInterval(updatePage);
      }
    }
  },
	render:function() {
		return (
			<Body
        users={this.props.users}
        toggleAllTime={this.toggleAllTime}
        toggleTop30={this.toggleTop30}
			/>
		);
	}
});

// App Component holds the ajax requests for the top30 Data and allTime Data.
// It passes the data from these requests down via the arrays in its state.
// It also passes down whether the top30 or allTime data is currently active.
// And determines whether to make a new ajax request or use the already cached data if possible
var App = React.createClass({
	propTypes: {
		url: PropTypes.string.isRequired
	},
	getInitialState: function() {
		return {
      top30: [],
      allTime: [],
			active: 'top30'
		}
	},
	getTop30Data: function() {
		$.ajax({
			method:'get',
			url:this.props.url + 'recent',
			success: function(data) {
				this.setState({top30: data});
			}.bind(this)
		});
	},
	getAllTimeData: function() {
		$.ajax({
			method:'get',
			url:this.props.url + 'alltime',
			success: function(data) {
				this.setState({allTime: data});
			}.bind(this)
		});
	},
	//make ajax request if data is not already cached, otherwise just used the cached data
	handleDataToggle: function() {
		this.state.active === 'top30'
    ? this.setState({active: 'allTime'}, function() {
        if (!this.state.allTime.length) {
          this.getAllTimeData();
          $('#allTime_icon').toggleClass('disabled');
          
        }
        else { $('#allTime_icon').toggleClass('disabled'); }
			})
		: this.setState({active: 'top30'}, function() {
				if (!this.state.top30.length) {this.getTop30Data(); }
        else { $('#top30_icon').toggleClass('disabled'); }
			});
	},
	//make ajax request on app load & animate loading
	componentWillMount: function() {
		this.getTop30Data();
    setInterval(function() {
          $('tr.disabled:first').fadeIn().toggleClass('disabled');
        }, 100); 
	},
	render: function() {
		return (
			  <main>
					<Header />
					<BodyContainer
						users={this.state[this.state.active]}
						active={this.state.active}
						onDataToggle={this.handleDataToggle} />
					<Footer />
			  </main>
		);
	}
});

/* Base URL to retrieve data from is passed into App component */
ReactDOM.render(
	<App url='https://fcctop100.herokuapp.com/api/fccusers/top/' />,
	document.getElementById('app')
);

              
            
!
999px

Console