-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdates.js
136 lines (124 loc) · 3.19 KB
/
dates.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
import React from 'react';
import {connect} from 'react-redux';
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native';
import DateForm from './dateForm';
import {getDates} from './_action';
import Heart from '../../assets/love.png';
import Placeholder from '../../components/placeholder';
import {NavigationEvents} from 'react-navigation';
import Loading from '../../components/loading';
class Dates extends React.Component {
constructor(props) {
super(props);
this.state = {
showForm: false,
loading: true,
};
this.hideForm = this.hideForm.bind(this);
this.getDates = this.getDates.bind(this);
}
getDates() {
this.setState({loading: true}, async () => {
await this.props.getDate();
this.setState({loading: false});
});
}
hideForm() {
this.setState({showForm: false});
}
render() {
if (this.state.loading) {
return <View>
<NavigationEvents onWillFocus={this.getDates} />
<Loading />
</View>;
}
const Button = <TouchableOpacity style={styles.requestDateButton} onPress={() => this.setState({showForm: true})}>
<Text style={styles.requestDateButtonText}>{ this.props.dates.length > 0 ? 'Edit Date' : 'New Date' }</Text>
</TouchableOpacity>;
return (
<View style={styles.container}>
<NavigationEvents onWillFocus={this.getDates} />
{Button}
{this.state.showForm && <DateForm close={this.hideForm} />}
{this.props.dates.length > 0 && <View style={styles.date}>
{this.props.dates.map((date) => (<View key={date.id}>
<Text style={styles.dateText}>
{ date.activity }
{ ' @' } { date.time || 'any time' }
{ ' in' } { date.city }
</Text>
</View>))}
</View>}
{this.props.dates.length === 0 && (
<Placeholder
icon={Heart}
headerText="You don't have a date, yet"
subText="Add a new date or try sending a request"
/>
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
paddingTop: 50,
},
image: {
borderRadius: 50,
borderWidth: 5,
borderColor: 'white',
height: 100,
width: 100,
position: 'absolute',
top: -10,
zIndex: 100,
},
detailContainer: {
padding: 20,
borderRadius: 20,
marginLeft: 60,
paddingLeft: 50,
flex: 1,
backgroundColor: 'white',
},
requestDateButton: {
backgroundColor: 'red',
borderRadius: 10,
padding: 10,
},
requestDateButtonText: {
color: 'white',
},
requestButton: {
backgroundColor: 'red',
position: 'absolute',
borderRadius: 10,
padding: 5,
paddingLeft: 10,
paddingRight: 10,
top: -10,
right: 10,
},
requestButtonText: {
color: 'white',
fontSize: 12,
},
date: {
backgroundColor: 'white',
borderRadius: 10,
},
dateText: {
color: '#222',
margin: 20,
},
});
const mapStateToProps = (state) => ({
dates: state.dates,
user_id: state.session.id,
});
const mapDispatchToProps = (dispatch) => ({
getDate: () => dispatch(getDates()),
});
export default connect(mapStateToProps, mapDispatchToProps)(Dates);