// @flow import * as React from 'react'; import {Avatar, Card, List, ProgressBar, Subheading, withTheme} from "react-native-paper"; import {FlatList, StyleSheet} from "react-native"; import i18n from 'i18n-js'; import type {team} from "../../../screens/Amicale/VoteScreen"; import type {CustomTheme} from "../../../managers/ThemeManager"; type Props = { teams: Array, dateEnd: string, theme: CustomTheme, } class VoteResults extends React.Component { totalVotes: number; winnerIds: Array; constructor(props) { super(); props.teams.sort(this.sortByVotes); this.getTotalVotes(props.teams); this.getWinnerIds(props.teams); } shouldComponentUpdate() { return false; } sortByVotes = (a: team, b: team) => b.votes - a.votes; getTotalVotes(teams: Array) { this.totalVotes = 0; for (let i = 0; i < teams.length; i++) { this.totalVotes += teams[i].votes; } } getWinnerIds(teams: Array) { 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: team) => item.id.toString(); resultRenderItem = ({item}: { item: team }) => { const isWinner = this.winnerIds.indexOf(item.id) !== -1; const isDraw = this.winnerIds.length > 1; const colors = this.props.theme.colors; return ( isWinner ? : null} titleStyle={{ color: isWinner ? colors.primary : colors.text }} style={{padding: 0}} /> ); }; render() { return ( } /> {i18n.t('screens.vote.results.totalVotes') + ' ' + this.totalVotes} {/*$FlowFixMe*/} ); } } const styles = StyleSheet.create({ card: { margin: 10, }, icon: { backgroundColor: 'transparent' }, }); export default withTheme(VoteResults);