forked from vergnet/application-amicale
Fixed vote api errors and handle draw
This commit is contained in:
parent
0ba48adb6e
commit
d032b80158
4 changed files with 29 additions and 13 deletions
|
@ -13,7 +13,7 @@ type Props = {
|
|||
class VoteResults extends React.Component<Props> {
|
||||
|
||||
totalVotes: number;
|
||||
winnerId: number;
|
||||
winnerIds: Array<number>;
|
||||
colors: Object;
|
||||
|
||||
constructor(props) {
|
||||
|
@ -21,7 +21,7 @@ class VoteResults extends React.Component<Props> {
|
|||
this.colors = props.theme.colors;
|
||||
props.teams.sort(this.sortByVotes);
|
||||
this.getTotalVotes(props.teams);
|
||||
this.getWinnerId(props.teams);
|
||||
this.getWinnerIds(props.teams);
|
||||
}
|
||||
|
||||
shouldComponentUpdate() {
|
||||
|
@ -37,14 +37,21 @@ class VoteResults extends React.Component<Props> {
|
|||
}
|
||||
}
|
||||
|
||||
getWinnerId(teams: Array<Object>) {
|
||||
this.winnerId = teams[0].id;
|
||||
getWinnerIds(teams: Array<Object>){
|
||||
let max = teams[0].votes;
|
||||
this.winnerIds= [];
|
||||
for (let i = 0; i < teams.length; i++) {
|
||||
if (teams[i].votes === max)
|
||||
this.winnerIds.push(teams[i].id);
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
voteKeyExtractor = (item: Object) => item.id.toString();
|
||||
|
||||
resultRenderItem = ({item}: Object) => {
|
||||
const isWinner = this.winnerId === item.id;
|
||||
const isWinner = this.winnerIds.indexOf(item.id) !== -1;
|
||||
return (
|
||||
<Card style={{
|
||||
marginTop: 10,
|
||||
|
|
|
@ -45,7 +45,7 @@ export default class VoteSelect extends React.PureComponent<Props, State> {
|
|||
return new Promise((resolve, reject) => {
|
||||
ConnectionManager.getInstance().authenticatedRequest(
|
||||
"elections/vote",
|
||||
{"vote": parseInt(this.state.selectedTeam)})
|
||||
{"team": parseInt(this.state.selectedTeam)})
|
||||
.then(() => {
|
||||
this.onVoteDialogDismiss();
|
||||
this.props.onVoteSuccess();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as React from 'react';
|
||||
import i18n from "i18n-js";
|
||||
import {ERROR_TYPE} from "../../managers/ConnectionManager";
|
||||
import {ERROR_TYPE} from "../../utils/WebData";
|
||||
import AlertDialog from "./AlertDialog";
|
||||
|
||||
type Props = {
|
||||
|
|
|
@ -9,12 +9,13 @@ import VoteTease from "../../components/Amicale/Vote/VoteTease";
|
|||
import VoteSelect from "../../components/Amicale/Vote/VoteSelect";
|
||||
import VoteResults from "../../components/Amicale/Vote/VoteResults";
|
||||
import VoteWait from "../../components/Amicale/Vote/VoteWait";
|
||||
import {Button} from "react-native-paper";
|
||||
|
||||
const FAKE_DATE = {
|
||||
"date_begin": "2020-04-07 21:50",
|
||||
"date_end": "2020-04-06 23:50",
|
||||
"date_result_begin": "2020-04-06 21:50",
|
||||
"date_result_end": "2020-04-07 22:50",
|
||||
"date_begin": "2020-04-09 15:50",
|
||||
"date_end": "2020-04-09 15:50",
|
||||
"date_result_begin": "2020-04-09 15:50",
|
||||
"date_result_end": "2020-04-09 22:50",
|
||||
};
|
||||
|
||||
const FAKE_DATE2 = {
|
||||
|
@ -43,13 +44,18 @@ const FAKE_TEAMS2 = {
|
|||
{
|
||||
id: 1,
|
||||
name: "TEST TEAM1",
|
||||
votes: 1,
|
||||
votes: 9,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "TEST TEAM2",
|
||||
votes: 9,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "TEST TEAM3",
|
||||
votes: 5,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
@ -158,6 +164,9 @@ export default class VoteScreen extends React.Component<Props, State> {
|
|||
extraData={this.state.hasVoted.toString()}
|
||||
renderItem={this.mainRenderItem}
|
||||
/>
|
||||
<Button onPress={this.reloadData}>
|
||||
REFRESH
|
||||
</Button>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
@ -223,7 +232,7 @@ export default class VoteScreen extends React.Component<Props, State> {
|
|||
mandatory: false,
|
||||
},
|
||||
{
|
||||
link: 'elections/datesString',
|
||||
link: 'elections/dates',
|
||||
params: {},
|
||||
mandatory: false,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue