-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChallenges.js
75 lines (65 loc) · 1.62 KB
/
Challenges.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
import React from 'react-native';
const { StyleSheet, View, Text } = React;
const styles = StyleSheet.create(require('./styles.js'));
import Challenge from './Challenge/Challenge';
const MOCKED_DATA = {
activeChallenges: [
{
id: 123,
name: 'LLL 2016 Challenge',
fineAmount: 1000,
fineCurrency: 'kr',
members: [
{
email: '[email protected]',
name: 'Louise Lizell',
activities: {
},
},
{
email: '[email protected]',
name: 'Louise Hamilton',
},
{
email: '[email protected]',
name: 'Lotta Nyman',
},
],
},
],
};
export default class Challenges extends React.Component {
constructor(props) {
super(props);
this.state = { activeChallenges: [] };
}
componentDidMount() {
this.fetchData();
}
fetchData() {
this.setState({ activeChallenges: MOCKED_DATA.activeChallenges });
}
renderCreate() {
return (<Text style={styles.instructions}>You do not have any active challenges.</Text>);
}
renderChallenges() {
const activeChallenges = this.state.activeChallenges;
let key = 1;
return (
<View>
{ activeChallenges.map(challenge => <Challenge challenge={challenge} key={`c${key++}`}/>) }
</View>
);
}
render() {
const activeChallenges = this.state.activeChallenges;
return (
<View style={styles.challenges}>
{ activeChallenges && activeChallenges.length > 0
? this.renderChallenges()
: this.renderCreate()
}
</View>
);
}
}