From 93086c11affecd2dc51a82230567fbc17587ccb5 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Fri, 29 Jun 2018 14:39:07 -0400 Subject: [PATCH] add sorting functions for polls filter --- app/components/simple-voting/PollsList.js | 13 +++++++++++-- app/dapp.js | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/components/simple-voting/PollsList.js b/app/components/simple-voting/PollsList.js index 531d827..be264fb 100644 --- a/app/components/simple-voting/PollsList.js +++ b/app/components/simple-voting/PollsList.js @@ -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 = () => ( - {({ updatePoll, rawPolls }) => + {({ updatePoll, rawPolls, pollOrder }) => - {rawPolls.map((poll, idx) => )} + {rawPolls + .map((poll, i) => ({ ...poll, idPoll: i }) ) + .sort(sortingFn[pollOrder]) + .map((poll, idx) => )} } diff --git a/app/dapp.js b/app/dapp.js index c18b24d..538b947 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -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(() => {