Last active
October 26, 2016 18:49
-
-
Save Breta01/2952086da1b4afe4b5a8b6ea32f26cb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Table from './Table'; | |
const Dashboard = React.createClass({ | |
// Function where the magic happens :D | |
sort_by: function(field, reverse, primer) { | |
var key = primer ? function(x) {return primer(x[field])} : | |
function(x) {return x[field]}; | |
reverse = !reverse ? 1 : -1; | |
return function (a, b) { | |
return a = key(a), b = key(b), reverse * ((a > b) - (b > a)); | |
}; | |
}, | |
render: function() { | |
const { stats } = this.props; | |
// Sorting by timestamp and reversing order | |
stats.sort(this.sort_by('timestamp', true)); | |
return ( | |
<div className="dashboard"> | |
<h1>Dashboard</h1> | |
<Table stats={stats.slice(0, 10)} /> | |
</div> | |
); | |
} | |
}); | |
export default Dashboard; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment