add sorting functions for polls filter

This commit is contained in:
Barry Gitarts 2018-06-29 14:39:07 -04:00
parent c8b22e737d
commit 93086c11af
2 changed files with 12 additions and 3 deletions

View File

@ -12,6 +12,12 @@ import web3 from "Embark/web3"
import CircularProgress from '@material-ui/core/CircularProgress';
import { VotingContext } from '../../context';
const sortingFn = {
MOST_VOTES: (a, b) => b._qvResults - a._qvResults,
MOST_VOTERS: (a, b) => b._voters - a._voters,
NEWEST_ADDED: (a, b) => b._startBlock - a._startBlock,
ENDING_SOONEST: (a, b) => a._endBlock - b._endBlock
};
class Poll extends Component {
constructor(props){
@ -113,9 +119,12 @@ class Poll extends Component {
const PollsList = () => (
<VotingContext.Consumer>
{({ updatePoll, rawPolls }) =>
{({ updatePoll, rawPolls, pollOrder }) =>
<Fragment>
{rawPolls.map((poll, idx) => <Poll key={idx} idPoll={idx} updatePoll={updatePoll} {...poll} />)}
{rawPolls
.map((poll, i) => ({ ...poll, idPoll: i }) )
.sort(sortingFn[pollOrder])
.map((poll, idx) => <Poll key={idx} updatePoll={updatePoll} {...poll} />)}
</Fragment>
}
</VotingContext.Consumer>

View File

@ -25,7 +25,7 @@ class App extends React.Component {
constructor(props) {
super(props);
}
state = { admin: false };
state = { admin: false, pollOrder: 'NEWEST_ADDED' };
componentDidMount(){
__embarkContext.execWhenReady(() => {