mirror of
https://github.com/status-im/visual-identity.git
synced 2025-02-08 10:44:33 +00:00
add sorting functions for polls filter
This commit is contained in:
parent
c8b22e737d
commit
93086c11af
@ -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>
|
||||
|
@ -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(() => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user