-
Notifications
You must be signed in to change notification settings - Fork 23
/
app.js
108 lines (102 loc) · 2.28 KB
/
app.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
import React from 'react';
import { connect } from 'react-redux';
import { addPerson, deletePerson } from './actions';
import {
StyleSheet,
Text,
View,
TextInput,
TouchableHighlight,
} from 'react-native';
class App extends React.Component {
state = {
inputValue: '',
}
addPerson = () => {
if (this.state.inputValue === '') return;
this.props.dispatchAddPerson({
name: this.state.inputValue,
});
this.setState({ inputValue: '' });
}
deletePerson = (person) => {
this.props.dispatchdeletePerson(person)
}
updateInput = (inputValue) => {
this.setState({ inputValue })
}
render() {
return (
<View style={styles.container}>
<Text style={styles.title}>People</Text>
<TextInput
onChangeText={text => this.updateInput(text)}
style={styles.input}
value={this.state.inputValue}
placeholder="Name"
/>
<TouchableHighlight
underlayColor="#ffa012"
style={styles.button}
onPress={this.addPerson}
>
<Text style={styles.buttonText}>Add Person</Text>
</TouchableHighlight>
{
this.props.people.map((person, index) => (
<View key={index} style={styles.person}>
<Text>Name: {person.name}</Text>
<Text onPress={() => this.deletePerson(person)}>Delete Person</Text>
</View>
))
}
</View>
)
}
}
const styles = StyleSheet.create({
container: {
marginTop: 20,
padding: 20,
},
title: {
fontSize: 22,
textAlign: 'center',
},
input: {
backgroundColor: '#e4e4e4',
height: 55,
borderRadius: 3,
padding: 5,
marginTop: 12,
},
button: {
backgroundColor: '#ff9900',
height: 60,
justifyContent: 'center',
alignItems: 'center',
marginTop: 12,
borderRadius: 3,
},
buttonText: {
color: 'white',
},
person: {
marginTop: 12,
},
});
function mapStateToProps (state) {
return {
people: state.people.people
}
}
function mapDispatchToProps (dispatch) {
return {
dispatchAddPerson: (person) => dispatch(addPerson(person)),
dispatchdeletePerson: (person) => dispatch(deletePerson(person))
}
}
export default connect(
mapStateToProps,
mapDispatchToProps,
)(App)