Camper Leaderboard
How do I make an camper leaderboard?
This is a Freecodecamp leaderboard that ranks it's users by their points. You can sort the table by past 30 days points or all time points.. What is a camper leaderboard? How do you make a camper leaderboard? This script and codes were developed by Mihkel on 08 December 2022, Thursday.
Camper Leaderboard - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Camper Leaderboard</title> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'>
</head>
<body> <div id="main"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.min.js'></script>
<script src='https://cdn.jsdelivr.net/refluxjs/0.2.11/reflux.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fetch/0.11.0/fetch.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Camper Leaderboard - Script Codes JS Codes
"use strict";
var HTTP = { url: "https://fcctop100.herokuapp.com/api/fccusers/top/recent", get: function get() { return fetch(this.url).then(function (res) { return res.json(); }); }
};
var Actions = Reflux.createActions(["loadData", "sort"]);
var CamperStore = Reflux.createStore({ listenables: [Actions], loadData: function loadData() { HTTP.get().then(function (data) { this.campers = data; this.trigger(this.campers); }.bind(this)); }, sort: function sort(method) { this.campers.sort(function (a, b) { switch (method) { case "recentAsc": return a.recent - b.recent; case "recentDesc": return b.recent - a.recent; case "allTimeAsc": return a.alltime - b.alltime; case "allTimeDesc": return b.alltime - a.alltime; } }); this.trigger(this.campers); }
});
var TableRow = React.createClass({ displayName: "TableRow", render: function render() { var rowStyle = { textAlign: "center" }; var headerStyle = { marginTop: 27 }; var special = { float: "left" }; return React.createElement( "tr", { style: rowStyle }, React.createElement( "td", null, React.createElement( "h4", { style: headerStyle }, this.props.position ) ), React.createElement( "td", null, React.createElement( "h4", { style: special }, React.createElement("img", { src: this.props.avatarUrl, width: "50", height: "50", alt: "avatar" }), " ", React.createElement( "a", { href: "https://www.freecodecamp.com/" + this.props.name, target: "_blank" }, this.props.name ) ) ), React.createElement( "td", null, React.createElement( "h4", { style: headerStyle }, this.props.recentPoints ) ), React.createElement( "td", null, React.createElement( "h4", { style: headerStyle }, this.props.allTime ) ) ); }
});
var TableHead = React.createClass({ displayName: "TableHead", getInitialState: function getInitialState() { return { recentDesc: true, allTimeDesc: true, recentSort: true }; }, recentSort: function recentSort() { var method = ""; if (!this.state.recentSort) { method = this.state.recentDesc ? "recentDesc" : "recentAsc"; this.setState({ recentSort: true }); } else { method = this.state.recentDesc ? "recentAsc" : "recentDesc"; this.setState({ recentDesc: !this.state.recentDesc }); } Actions.sort(method); }, allTimeSort: function allTimeSort() { var method = ""; if (this.state.recentSort) { method = this.state.allTimeDesc ? "allTimeDesc" : "allTimeAsc"; this.setState({ recentSort: false }); } else { method = this.state.allTimeDesc ? "allTimeAsc" : "allTimeDesc"; this.setState({ allTimeDesc: !this.state.allTimeDesc }); } Actions.sort(method); }, render: function render() { var thStyle = { fontWeight: 700 }; var tableStyle = { textAlign: "center" }; var active = { background: "#3097d1", color: "#FFF", textAlign: "center", fontWeight: 700 }; var caretStyle = { fontSize: 24, cursor: "pointer" }; var recentIconClass = this.state.recentDesc ? "fa fa-caret-down" : "fa fa-caret-up"; var allTimeIconClass = this.state.allTimeDesc ? "fa fa-caret-down" : "fa fa-caret-up"; return React.createElement( "thead", null, React.createElement( "tr", null, React.createElement( "th", { style: tableStyle }, React.createElement( "h4", { style: thStyle }, "#" ) ), React.createElement( "th", { style: tableStyle }, React.createElement( "h4", { style: thStyle }, "Camper Name" ) ), React.createElement( "th", { style: this.state.recentSort ? active : tableStyle }, React.createElement( "h4", { style: thStyle }, "Points in past 30 days ", React.createElement("i", { className: recentIconClass, onClick: this.recentSort, style: caretStyle }) ) ), React.createElement( "th", { style: !this.state.recentSort ? active : tableStyle }, React.createElement( "h4", { style: thStyle }, "All time points ", React.createElement("i", { className: allTimeIconClass, onClick: this.allTimeSort, style: caretStyle }) ) ) ) ); }
});
var LeaderboardContainer = React.createClass({ displayName: "LeaderboardContainer", mixins: [Reflux.listenTo(CamperStore, "onTrigger")], getInitialState: function getInitialState() { return { campers: [] }; }, componentWillMount: function componentWillMount() { Actions.loadData(); }, onTrigger: function onTrigger(data) { this.setState({ campers: data }); }, render: function render() { document.body.style.background = "#FAFAFA"; var panelStyle = { WebKitBoxShadow: "0 0 4px rgba(0, 0, 0, 0.4)", MozBoxShadow: "0 0 4px rgba(0, 0, 0, 0.4)", boxShadow: "0 0 4px rgba(0, 0, 0, 0.4)", marginTop: 30 }; var headingStyle = { color: "#3097d1", fontWeight: 700, textAlign: "center" }; var camperArr = []; this.state.campers.forEach(function (item, index) { camperArr.push(React.createElement(TableRow, { key: index + item.username, position: index + 1, name: item.username, recentPoints: item.recent, allTime: item.alltime, avatarUrl: item.img })); }); return React.createElement( "div", { className: "container" }, React.createElement( "div", { className: "row" }, React.createElement( "div", { className: "col-sm-12" }, React.createElement( "div", { className: "panel panel-default", style: panelStyle }, React.createElement( "div", { className: "panel-heading" }, React.createElement( "h3", { style: headingStyle }, "Camper Leaderboard" ) ), React.createElement( "div", { className: "table-responsive" }, React.createElement( "table", { className: "table table-striped table-bordered" }, React.createElement(TableHead, null), React.createElement( "tbody", null, camperArr ) ) ) ) ) ) ); }
});
ReactDOM.render(React.createElement(LeaderboardContainer, null), document.getElementById("main"));
Developer | Mihkel |
Username | Krokodill |
Uploaded | December 08, 2022 |
Rating | 3 |
Size | 4,964 Kb |
Views | 8,096 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
React Weather Broadcast | 6,708 Kb |
Random Quote Machine | 2,692 Kb |
Form validation with jQuery | 2,641 Kb |
React.js Game of Life | 5,760 Kb |
Snake Game | 2,941 Kb |
Dungeon Crawler | 5,057 Kb |
Game of Life | 2,922 Kb |
React Markdown Preview | 2,675 Kb |
Pomodoro Timer | 3,599 Kb |
Simon Game | 4,975 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Blog Concept 2 | JGallardo | 2,994 Kb |
Wikipedia Viewer | Codinger | 4,681 Kb |
Cartoon Bomb | Tcmulder | 4,929 Kb |
Scroll Arrow | Robooneus | 4,437 Kb |
CSS Grid Test | Ajaykarwal | 2,377 Kb |
Navier Stoke Fluid Simulation | Esimov | 8,584 Kb |
Process Accordion | Devilskitchen | 31,432 Kb |
CSS 3D Radio buttons | Andreasnylin | 1,650 Kb |
Segments mouse following | Nosir | 2,909 Kb |
Improved Page Flipping Effect | Usaphp | 5,201 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!