-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
132 lines (124 loc) · 3.79 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React, { Component } from 'react';
import { FlatList, Alert } from 'react-native';
import { connect } from 'react-redux';
import { Container, Content } from 'native-base';
import HeaderComp from './src/components/general/Header';
import FooterComp from './src/components/general/Footer';
import ListItemComp from './src/components/general/ListItem';
import Spinner from './src/components/Spinner';
import { addExpense, deleteExpense, updateExpense, changeDate } from './src/store/actions';
class App extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true
};
this.onEditPress = this.onEditPress.bind(this);
this.updateExpense = this.updateExpense.bind(this);
this.onPressAddExpense = this.onPressAddExpense.bind(this);
};
componentDidMount() {
this.props.onDateChange(new Date());
setTimeout(() => {
this.setState({ isLoading: false });
}, 2000);
}
onPressAddExpense() {
this.props.navigator.push({
screen: 'HarcaMA.AddExpense',
title: 'Harcama Ekle',
navigatorStyle: {
navBarBackgroundColor: '#1DAA80',
navBarTextColor: 'white',
navBarButtonColor: 'white',
statusBarColor: '#167F60'
},
passProps: {
addExpense: data => this.props.onAddExpense(data),
}
});
}
onDeletePress(deleteItem) {
Alert.alert(
'',
'Silmek istediğinize emin misiniz?',
[
{text: 'İptal', onPress: () => {}, style: 'cancel'},
{text: 'Sil', onPress: () => this.props.onDeleteExpense(deleteItem) },
],
{
cancelable: false,
}
);
}
updateExpense(updateItem) {
this.props.onUpdateExpense(updateItem);
}
onEditPress(item) {
this.props.navigator.push({
screen: 'HarcaMA.EditExpense',
title: 'Harcama Düzenle',
navigatorStyle: {
navBarBackgroundColor: '#1DAA80',
navBarTextColor: 'white',
navBarButtonColor: 'white',
statusBarColor: '#167F60'
},
passProps: {
state: item,
updateExpense: item => this.updateExpense(item),
deleteExpense: (item) => this.onDeletePress(item),
expenseTypes: this.props.expenseTypes
}
});
}
render() {
if(this.state.isLoading) {
return (
<Spinner />
);
}
else {
return <Container>
<HeaderComp
chosenDate={this.props.chosenDate}
setDate={(date) => this.props.onDateChange(date)}
onToggle={this.onPressAddExpense}
onIconPress={() => { this.props.navigator.toggleDrawer(); }}
/>
<Content style={{ backgroundColor: '#f9f9f9' }} padder>
<FlatList
data={this.props.dailyExpense}
renderItem={ ({ item }) => {
return (
<ListItemComp
edit={() => {this.onEditPress(item)}}
delete={() => this.onDeletePress(item)}
item={item}
/>
);
}}
keyExtractor={item => item.id.toString()}
/>
</Content>
<FooterComp
todayExpense={this.props.todayExpense}
thisMonthExpense={this.props.totalMonthExpense}
/>
</Container>;
}
}
}
const mapStateToProps = ({ expense }) =>{
const { chosenDate, dailyExpense, todayExpense, totalMonthExpense } = expense;
return { chosenDate, dailyExpense, todayExpense, totalMonthExpense };
};
const mapDispatchToProps = dispatch => {
return {
onDateChange: date => dispatch(changeDate(date)),
onAddExpense: data => dispatch(addExpense(data)),
onDeleteExpense: data => dispatch(deleteExpense(data)),
onUpdateExpense: data => dispatch(updateExpense(data))
};
};
export default connect(mapStateToProps, mapDispatchToProps)(App);