-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeeks.js
145 lines (140 loc) · 4.74 KB
/
Weeks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
ListView,
TouchableHighlight,
Animated,
TabBarIOS
} = React;
var Games = require('./Games');
var Scores = require('./Scores');
var TeamImages = require('./TeamImages');
var ParseHelper = require('./ParseHelper');
class Week extends React.Component{
constructor(props){
//perform base constructor
super(props);
//set the properties of the DataSource
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 != r2
});
//set the state, including the starting tab and the initial week data (hardcoded since weeks don't change)
this.state = {
dataSource: ds.cloneWithRows([{week:'1',date:'Sept 10'},{week:2,date:'Sept 17'},{week:3,date:'Sept 14'},{week:4,date:'Oct 1'},{week:5,date:'Oct 8'},{week:6,date:'Oct 15'},{week:7,date:'Oct 22'},{week:8,date:'Nov 1'},{week:9,date:'Nov 5'},{week:10,date:'Nov 12'},{week:11,date:'Nov 19'},{week:12,date:'Nov 26'},{week:13,date:'Dec 3'},{week:14,date:'Dec 10'},{week:15,date:'Dec 17'},{week:16,date:'Dec 24'},{week:17,date:'Jan 3'}, ]),
selectedTab:'pick',
images : TeamImages
}
}
//handle when a user presses a row
pressRow(rowData){
//get the score of that user for the week the user pushed, returns a promise with the score
ParseHelper.getScoreForCurrentUser(rowData.week)
.then(score =>{
//push a new Games 'scene' onto the navigator, pass info about the user as props
this.props.navigator.push({
title: 'Week '+ rowData.week + ' Score: '+score,
component: Games,
passProps:{
week:rowData.week,
images:this.state.images,
actAsAdmin:this.state.selectedTab == 'results',
league:this.props.league
}
})
})
}
//what each row should look like
renderRow(rowData){
return (
//make the rows touchable and tell it to do the pressRow function when pressed
//show the week number, and the date. Use styles to position the info.
//if the user is an Admin and we are in the results tab, then make the background a different color.
<TouchableHighlight
onPress={()=> this.pressRow(rowData)}
underlayColor = '#ddd'>
<View style ={[styles.row,this.state.selectedTab == 'results' &&{backgroundColor: '#333'}]}>
<Text style={{fontSize:18}}>Week {rowData.week}</Text>
<View style ={styles.rowText}>
<Text style ={styles.dateText}>{rowData.date}</Text>
</View>
</View>
</TouchableHighlight>
)
}
render(){
//define a variable that will be the results tab if the user is an admin, otherwise will be empty and will not show.
var adminControls;
if (this.props.isAdmin) {
//declare what the results tab would look like.
adminControls=
<TabBarIOS.Item
title = 'Enter Results'
selected = {this.state.selectedTab == 'results'}
onPress = {() => this.setState({selectedTab:'results'}) }>
<View style = {styles.container}>
<ListView
dataSource = {this.state.dataSource}
renderRow = {this.renderRow.bind(this)}>
</ListView>
</View>
</TabBarIOS.Item>;
};
//declare what the component will look like.
//define the tab bad and the 2 items that will be in the tab bar and what each will look like when selected
//if scores is selected, show a Scores Component
//if user isAdmin, adminControls will contain an react component and will be displayed with the other tabs
return (
<TabBarIOS>
<TabBarIOS.Item
title= 'Pick'
selected = {this.state.selectedTab == 'pick'}
onPress = {()=>this.setState({selectedTab: 'pick'})}>
<View style = {styles.container}>
<ListView
dataSource = {this.state.dataSource}
renderRow = {this.renderRow.bind(this)}>
</ListView>
</View>
</TabBarIOS.Item>
<TabBarIOS.Item
title = 'Scores'
selected = {this.state.selectedTab == 'scores'}
onPress = {()=>this.setState({selectedTab:'scores'})}>
<Scores username = {this.props.username} league = {this.props.league}/>
</TabBarIOS.Item>
{adminControls}
</TabBarIOS>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
paddingTop:40,
justifyContent: 'flex-start',
},
row:{
flex:1,
flexDirection:'row',
padding:18,
borderBottomWidth: 1,
borderColor: '#d7d7d7',
},
dateText:{
fontSize:15,
color:'#b5b5b5',
textAlign:'right'
},
rowText:{
flex:1,
}
});
module.exports = Week