css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              body
	font-family: 'Roboto', sans-serif
	font-size: 18px
	color: #222
	background: #eef
	margin: 0

header
	text-align: center
	color: #eee
	background: #3949AB
	padding: 25px 0
	font-size: 1.1em

.Leaderboard
	margin: 30px auto
	max-width: 850px
	min-width: 750px
	background: #fff
	
	h1
		text-align: center
		font-size: 25px
		font-weight: 400
		color: #fff
		margin: 0
		padding: 8px 0
		background: #007E00
		border: 1px solid #939393
		border-bottom: none
		border-radius: 4px 4px 0 0

	table
		border: 1px solid #939393
		border-top: none
		border-radius: 0 0 4px 4px
		width: 100%

		td, th
			padding: 5px 0
		th:nth-child(1), th:nth-child(2)
			text-align: left
		td:nth-child(3), td:nth-child(4)
			text-align: center
		td:nth-child(2)
			display: flex
			align-items: center
		td:nth-child(1), td:nth-child(2), th:nth-child(1), th:nth-child(2)
			padding-left: 5px
		tr:nth-child(odd)
			background: #eee

		.camper-name
			margin-left: 10px

		img
			border-radius: 5px
			border: 1px solid #777

		.up-arrow, .down-arrow
			
			&:hover
				cursor: pointer
				user-select: none

		.up-arrow
			margin-left: 7px

		.down-arrow
			margin-left: -1px
	
footer
	position: absolute
	bottom: 0
	width: 100%
	text-align: center
	color: #eee
	background: #3949AB
	padding: 25px 0
	
            
          
!
            
              class App extends React.Component {
	constructor(props) {
		super(props);
	}
	render () {
		return (
			<div>
				<Header/>
				<Leaderboard/>
				<Footer/>
			</div>
		);
	}
};

const Header = () => {
	return (
		<div className="Header">
			<header>
				<h1>freeCodeCamp Leaderboard</h1>
				<p>Sort by brownie points scored in the last month or by all time high score.</p>
			</header>
		</div>
	);
};

const Footer = () => {
	return (
		<div className="Footer">
			<footer>a freeCodeCamp project by kbaig</footer>
		</div>
	);
};

class Leaderboard extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			recent: [],
			allTime: [],
			recentOrder: 'desc',
			allTimeOrder: null
		};
		this.sortRecentAsc = this.sortRecentAsc.bind(this);
		this.sortRecentDesc = this.sortRecentDesc.bind(this);
		this.toggleRecentOrder = this.toggleRecentOrder.bind(this);
		this.sortAllTimeAsc = this.sortAllTimeAsc.bind(this);
		this.sortAllTimeDesc = this.sortAllTimeDesc.bind(this);
		this.toggleAllTimeOrder = this.toggleAllTimeOrder.bind(this);
	}
	
	sortRecentAsc() {
		const recent = this.state.recent.sort((a,b) => a.rank > b.rank ? -1 : 1);
		this.setState({
			recent,
			recentOrder: 'asc',
			allTimeOrder: null
		});
	}
	
	sortRecentDesc() {
		const recent = this.state.recent.sort((a,b) => a.rank < b.rank ? -1 : 1);
		this.setState({
			recent,
			recentOrder: 'desc',
			allTimeOrder: null
		});
	}
	
	toggleRecentOrder() {
		!this.state.recentOrder || this.state.recentOrder === 'desc' ? this.sortRecentAsc() : this.sortRecentDesc();
	}
	
	sortAllTimeAsc() {
		const allTime = this.state.allTime.sort((a,b) => a.rank < b.rank ? -1 : 1);
		this.setState({
			allTime,
			recentOrder: null,
			allTimeOrder: 'asc'
		});
	}
	
	sortAllTimeDesc() {
		const allTime = this.state.allTime.sort((a,b) => a.rank > b.rank ? -1 : 1);
		this.setState({
			allTime,
			recentOrder: null,
			allTimeOrder: 'desc'
		});
	}
	
	toggleAllTimeOrder() {
		!this.state.allTimeOrder || this.state.allTimeOrder === 'desc' ? this.sortAllTimeAsc() : this.sortAllTimeDesc();
	}
	
	componentWillMount() {
		fetch('https://fcctop100.herokuapp.com/api/fccusers/top/recent')
			.then(res => res.json())
			.then(json => {
				json.map((camper, i) => {
					camper.rank = i + 1;
				});
				this.setState({ recent: json });
		})
			.catch(err => console.log(`fetch error: ${err}`));
		
		fetch('https://fcctop100.herokuapp.com/api/fccusers/top/alltime')
			.then(res => res.json())
			.then(json => {
				json.map((camper, i) => {
					camper.rank = i + 1;
				});
				this.setState({ allTime: json });
		})
			.catch(err => console.log(`fetch error: ${err}`));
	}
	
	render() {
		const campers = this.state.recentOrder ? this.state.recent : this.state.allTime;
		const rankings = campers.map((camper) => {
			return (
				<tr key={camper.name}>
					<td>{camper.rank}</td>
					<td>
						<img src={camper.img} height='30px' width='30px' alt=''/>
						<span className="camper-name">{camper.username}</span>
					</td> 
					<td>{camper.recent}</td>
					<td>{camper.alltime}</td>
				</tr>
			);
		});
		
		return (
			<div className="Leaderboard">
				<h1>Leaderboard</h1>
				<table>
 					<tr>
						<th>Rank</th>
						<th>Name</th> 
						<th>
							Recent
							<span onClick={this.toggleRecentOrder}>
								<span style={{color: this.state.recentOrder === 'asc' ? '#000' : '#aaa'}} className="up-arrow">&#8639;</span>
								<span style={{color: this.state.recentOrder === 'desc' ? '#000' : '#aaa'}} className="down-arrow">&#8642;</span>
							</span>
						</th>
						<th>
							All Time
							<span onClick={this.toggleAllTimeOrder}>
								<span style={{color: this.state.allTimeOrder === 'asc' ? '#000' : '#aaa'}} className="up-arrow">&#8639;</span>
								<span style={{color: this.state.allTimeOrder === 'desc' ? '#000' : '#aaa'}} className="down-arrow">&#8642;</span>
							</span>
						</th>
					</tr>
					{rankings}
				</table>
			</div>
		);
	}
};

// Render
ReactDOM.render(<App/>, document.getElementById('root'));
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console