forked from vergnet/application-amicale
Added basic vote display
This commit is contained in:
parent
db96700693
commit
98b1d267ec
2 changed files with 70 additions and 17 deletions
|
@ -36,6 +36,7 @@ class AuthenticatedScreen extends React.Component<Props, State> {
|
||||||
this.connectionManager = ConnectionManager.getInstance();
|
this.connectionManager = ConnectionManager.getInstance();
|
||||||
this.props.navigation.addListener('focus', this.onScreenFocus.bind(this));
|
this.props.navigation.addListener('focus', this.onScreenFocus.bind(this));
|
||||||
this.data = new Array(this.props.links.length);
|
this.data = new Array(this.props.links.length);
|
||||||
|
this.fetchData(); // TODO remove in prod (only use for fast refresh)
|
||||||
}
|
}
|
||||||
|
|
||||||
onScreenFocus() {
|
onScreenFocus() {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {ScrollView, StyleSheet} from "react-native";
|
import {FlatList, StyleSheet} from "react-native";
|
||||||
import {Avatar, Card, Paragraph, withTheme} from 'react-native-paper';
|
import {Avatar, Button, Card, Paragraph, RadioButton, withTheme} from 'react-native-paper';
|
||||||
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
||||||
import {stringToDate} from "../../utils/Planning";
|
import {stringToDate} from "../../utils/Planning";
|
||||||
|
|
||||||
|
@ -37,11 +37,15 @@ const FAKE_TEAMS = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {}
|
type State = {
|
||||||
|
selectedTeam: string,
|
||||||
|
}
|
||||||
|
|
||||||
class VoteScreen extends React.Component<Props, State> {
|
class VoteScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
state = {};
|
state = {
|
||||||
|
selectedTeam: "0",
|
||||||
|
};
|
||||||
|
|
||||||
colors: Object;
|
colors: Object;
|
||||||
|
|
||||||
|
@ -52,14 +56,30 @@ class VoteScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
today: Date;
|
today: Date;
|
||||||
|
|
||||||
|
mainFlatListData: Array<Object>;
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.colors = props.theme.colors;
|
this.colors = props.theme.colors;
|
||||||
this.hasVoted = false;
|
this.hasVoted = false;
|
||||||
this.teams = null;
|
this.teams = null;
|
||||||
this.today = new Date();
|
this.today = new Date();
|
||||||
|
|
||||||
|
this.mainFlatListData = [
|
||||||
|
{key: 'main'},
|
||||||
|
{key: 'info'},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainRenderItem = ({item}: Object) => {
|
||||||
|
if (item.key === 'info')
|
||||||
|
return this.getTitleCard();
|
||||||
|
else if (item.key === 'main' && this.isVoteAvailable())
|
||||||
|
return this.getContent();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
getScreen = (data: Array<Object>) => {
|
getScreen = (data: Array<Object>) => {
|
||||||
data[0] = FAKE_TEAMS;
|
data[0] = FAKE_TEAMS;
|
||||||
data[1] = FAKE_DATE;
|
data[1] = FAKE_DATE;
|
||||||
|
@ -72,16 +92,12 @@ class VoteScreen extends React.Component<Props, State> {
|
||||||
this.generateDateObject();
|
this.generateDateObject();
|
||||||
console.log(this.teams);
|
console.log(this.teams);
|
||||||
console.log(this.datesString);
|
console.log(this.datesString);
|
||||||
console.log(this.dates);
|
|
||||||
return (
|
return (
|
||||||
<ScrollView>
|
<FlatList
|
||||||
{
|
data={this.mainFlatListData}
|
||||||
this.isVoteAvailable()
|
extraData={this.state.selectedTeam}
|
||||||
? this.getContent()
|
renderItem={this.mainRenderItem}
|
||||||
: null
|
/>
|
||||||
}
|
|
||||||
{this.getTitleCard()}
|
|
||||||
</ScrollView>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -156,6 +172,14 @@ class VoteScreen extends React.Component<Props, State> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onVoteSelectionChange = (team: string) => {
|
||||||
|
this.setState({selectedTeam: team})
|
||||||
|
};
|
||||||
|
|
||||||
|
onVotePress = () => {
|
||||||
|
console.log("vote sent");
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user has not voted yet, and the votes are open
|
* The user has not voted yet, and the votes are open
|
||||||
*/
|
*/
|
||||||
|
@ -163,17 +187,45 @@ class VoteScreen extends React.Component<Props, State> {
|
||||||
return (
|
return (
|
||||||
<Card style={styles.card}>
|
<Card style={styles.card}>
|
||||||
<Card.Title
|
<Card.Title
|
||||||
title={"getVoteCard"}
|
title={"VOTE OPEN"}
|
||||||
subtitle={"getVoteCard"}
|
subtitle={"VOTE NOW"}
|
||||||
|
left={(props) => <Avatar.Icon
|
||||||
|
{...props}
|
||||||
|
icon={"alert-decagram"}
|
||||||
|
/>}
|
||||||
/>
|
/>
|
||||||
<Card.Content>
|
<Card.Content>
|
||||||
<Paragraph>TEAM1</Paragraph>
|
<RadioButton.Group
|
||||||
<Paragraph>TEAM2</Paragraph>
|
onValueChange={this.onVoteSelectionChange}
|
||||||
|
value={this.state.selectedTeam}
|
||||||
|
>
|
||||||
|
<FlatList
|
||||||
|
data={this.teams}
|
||||||
|
keyExtractor={this.voteKeyExtractor}
|
||||||
|
extraData={this.state.selectedTeam}
|
||||||
|
renderItem={this.voteRenderItem}
|
||||||
|
/>
|
||||||
|
</RadioButton.Group>
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
|
<Card.Actions>
|
||||||
|
<Button
|
||||||
|
icon="send"
|
||||||
|
mode="contained"
|
||||||
|
onPress={this.onVotePress}
|
||||||
|
style={{marginLeft: 'auto'}}>
|
||||||
|
SEND VOTE
|
||||||
|
</Button>
|
||||||
|
</Card.Actions>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
voteKeyExtractor = (item: Object) => item.id.toString();
|
||||||
|
|
||||||
|
voteRenderItem = ({item}: Object) => {
|
||||||
|
return <RadioButton.Item label={item.name} value={item.id.toString()}/>
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Votes have ended, results can be displayed
|
* Votes have ended, results can be displayed
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue