Compare commits

...

3 commits

4 changed files with 47 additions and 16 deletions

View file

@ -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,22 @@ 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;
const isDraw = this.winnerIds.length > 1;
return (
<Card style={{
marginTop: 10,
@ -54,7 +62,7 @@ class VoteResults extends React.Component<Props> {
title={item.name}
description={item.votes + ' ' + i18n.t('voteScreen.results.votes')}
left={props => isWinner
? <List.Icon {...props} icon="trophy" color={this.colors.primary}/>
? <List.Icon {...props} icon={isDraw ? "trophy-outline" : "trophy"} color={this.colors.primary}/>
: null}
titleStyle={{
color: isWinner

View file

@ -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();

View file

@ -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 = {

View file

@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import {FlatList, View} from "react-native";
import {FlatList, RefreshControl, View} from "react-native";
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
import {getTimeOnlyString, stringToDate} from "../../utils/Planning";
import VoteTitle from "../../components/Amicale/Vote/VoteTitle";
@ -11,10 +11,10 @@ import VoteResults from "../../components/Amicale/Vote/VoteResults";
import VoteWait from "../../components/Amicale/Vote/VoteWait";
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,16 +43,23 @@ 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,
},
],
};
const MIN_REFRESH_TIME = 5 * 1000;
type Props = {
navigation: Object
}
@ -75,6 +82,7 @@ export default class VoteScreen extends React.Component<Props, State> {
today: Date;
mainFlatListData: Array<Object>;
lastRefresh: Date;
authRef: Object;
@ -89,7 +97,15 @@ export default class VoteScreen extends React.Component<Props, State> {
]
}
reloadData = () => this.authRef.current.reload();
reloadData = () => {
let canRefresh;
if (this.lastRefresh !== undefined)
canRefresh = (new Date().getTime() - this.lastRefresh.getTime()) > MIN_REFRESH_TIME;
else
canRefresh = true;
if (canRefresh)
this.authRef.current.reload()
};
generateDateObject() {
this.dates = {
@ -140,6 +156,7 @@ export default class VoteScreen extends React.Component<Props, State> {
getScreen = (data: Array<Object | null>) => {
// data[0] = FAKE_TEAMS2;
// data[1] = FAKE_DATE;
this.lastRefresh = new Date();
if (data[1] === null)
data[1] = {date_begin: null};
@ -155,6 +172,12 @@ export default class VoteScreen extends React.Component<Props, State> {
{/*$FlowFixMe*/}
<FlatList
data={this.mainFlatListData}
refreshControl={
<RefreshControl
refreshing={false}
onRefresh={this.reloadData}
/>
}
extraData={this.state.hasVoted.toString()}
renderItem={this.mainRenderItem}
/>
@ -223,7 +246,7 @@ export default class VoteScreen extends React.Component<Props, State> {
mandatory: false,
},
{
link: 'elections/datesString',
link: 'elections/dates',
params: {},
mandatory: false,
},