fix voters page filterbar

This commit is contained in:
feruz 2019-12-03 19:45:00 +02:00
parent 5a87bffe05
commit cf56a4774e
2 changed files with 12 additions and 8 deletions

View File

@ -15,7 +15,7 @@ class AccountListContainer extends Component {
this.state = {
data: props.data,
filterResult: null,
filterIndex: '0',
filterIndex: 0,
};
}
@ -33,7 +33,7 @@ class AccountListContainer extends Component {
return itemName.indexOf(_text) > -1;
});
if (filterIndex !== '0') {
if (filterIndex !== 0) {
this._handleOnVotersDropdownSelect(filterIndex, '', newData);
} else {
this.setState({ filterResult: newData });
@ -45,13 +45,13 @@ class AccountListContainer extends Component {
const _data = Object.assign([], oldData || data);
switch (index) {
case '0':
case 0:
_data.sort((a, b) => Number(b.value) - Number(a.value));
break;
case '1':
case 1:
_data.sort((a, b) => b.percent - a.percent);
break;
case '2':
case 2:
_data.sort((a, b) => (isBefore(a.time, b.time) ? 1 : -1));
break;
default:
@ -74,7 +74,7 @@ class AccountListContainer extends Component {
};
render() {
const { data, filterResult } = this.state;
const { data, filterResult, filterIndex } = this.state;
const { children } = this.props;
return (
@ -82,6 +82,7 @@ class AccountListContainer extends Component {
children({
data,
filterResult,
filterIndex,
handleOnVotersDropdownSelect: this._handleOnVotersDropdownSelect,
handleSearch: this._handleSearch,
handleOnUserPress: this._handleOnUserPress,

View File

@ -23,7 +23,7 @@ const VotersScreen = ({ navigation }) => {
return (
<AccountListContainer data={activeVotes}>
{({ data, filterResult, handleOnVotersDropdownSelect, handleSearch }) => (
{({ data, filterResult, filterIndex, handleOnVotersDropdownSelect, handleSearch }) => (
<SafeAreaView style={globalStyles.container}>
<BasicHeader
title={`${headerTitle} (${data && data.length})`}
@ -37,7 +37,10 @@ const VotersScreen = ({ navigation }) => {
id: `voters_dropdown.${item}`,
}),
)}
defaultText={intl.formatMessage({ id: `voters_dropdown.${filterOptions[0]}` })}
defaultText={intl.formatMessage({
id: `voters_dropdown.${filterOptions[filterIndex]}`,
})}
selectedOptionIndex={filterIndex}
onDropdownSelect={handleOnVotersDropdownSelect}
/>
<VotersDisplay votes={filterResult || data} />