-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
206 lines (198 loc) · 5.73 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React from 'react';
import { StyleSheet, TouchableOpacity, Text, View, FlatList } from 'react-native';
import { Card, Container, Header, Button, Content, Title, Body, Right, Left, Icon } from 'native-base';
import { NativeRouter, Route, Link } from "react-router-native";
import Add from './src/components/Add';
import { Provider, connect } from 'react-redux';
import { createStore } from 'redux';
import reducer from './src/reducers';
import { SwipeListView } from 'react-native-swipe-list-view';
import moment from 'moment';
import db from './config';
import firebase from 'firebase';
import SignUp from './src/components/signUp';
import SignIn from './src/components/signIn';
const store = createStore(reducer);
const HabitCard = ({ item, addStreak, uid, habits }) => (
<TouchableOpacity onPress={() => addStreak(item, uid, habits)} style={styles.flatListContainer}>
<Card style={styles.flatlist}>
<Text style={styles.habit}> {item.habit} </Text>
<View style={styles.streak}>
<Text style={{ fontSize: 16}}> {item.streak} </Text>
</View>
</Card>
</TouchableOpacity>
);
//contentContainerStyle={{ justifyContent: 'center', flex: 1, alignItems: 'center' }}
class Home extends React.Component {
render() {
const { history, habits, weeklyHabitExist, dailyHabitExist, addStreak, uid } = this.props;
return (
<Container>
<Header>
<Left>
<Button transparent>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title>{ moment().format('MMMM Do')}</Title>
</Body>
<Right />
</Header>
<Content contentContainerStyle={{ flexGrow: 1, padding: 5, paddingTop: 10 }}>
{ dailyHabitExist && (
<View>
<View style={{ flex: 1, flexDirection: 'row' }}>
<Text style={{ marginTop: 10, color: '#007aff'}}> Daily Habits </Text>
<Text style={{ marginLeft: 'auto', marginRight: 12, marginTop: 10, color: '#D4AF37' }}> Streaks </Text>
</View>
<FlatList
data={Object.values(habits)}
renderItem={({item}) => {
if (item.time === 'daily') {
return (
<HabitCard item={item} habits={habits} uid={uid} addStreak={addStreak}/>
)
}
}}
/>
</View>
)}
{ weeklyHabitExist &&
<View style={styles.weeklyContainer}>
<Text style={styles.timeTitle}> Weekly Habits </Text>
<FlatList
data={Object.values(habits)}
renderItem={({item}) => {
console.log('item', item.time)
if (item.time === 'weekly') {
return (
<HabitCard item={item} uid={uid} habits={habits} addStreak={addStreak}/>
);
}}
}
/>
</View>
}
<View style={styles.addHabitContainer}>
<Button onPress={() => history.push('add')} block>
<Text style={styles.addBtn}> Add Habit </Text>
</Button>
</View>
</Content>
</Container>
);
}
}
const mapStateToProps = (state) => {
const { habits, weeklyHabitExist, dailyHabitExist, uid } = state;
console.log('THE STATE', state)
return {
habits,
weeklyHabitExist,
dailyHabitExist,
uid
}
}
const mapDispatchToProps = (dispatch) => {
return {
addStreak: (item, uid, habits) => {
const newItem = Object.assign({}, item);
console.log('item', item)
console.log('neItem', newItem)
console.log('habits', habits)
newItem.streak += 1;
console.log('habits', habits)
const newHabits = Object.assign({}, habits, { [item.habit]: newItem })
const habitRef = db.collection('habits').doc(uid);
habitRef.update({
habits: newHabits
});
dispatch({
type: 'ADD_STREAK',
item: newItem
})
},
}
}
const HomeContainer = connect(mapStateToProps, mapDispatchToProps)(Home)
export default function App() {
return (
<Provider store={store}>
<NativeRouter>
<Container>
<Content>
<Route exact path="/home" component={HomeContainer} />
<Route exact path="/add" component={Add} />
<Route exact path="/" component={SignIn} />
<Route exact path="/signUp" component={SignUp} />
</Content>
</Container>
</NativeRouter>
</Provider>
);
};
const styles = StyleSheet.create({
content: {
backgroundColor: 'red',
height: '100%'
},
habitsList: {
flexDirection: 'row'
},
weeklyContainer: {
marginTop: 10
},
flatListContainer: {
marginLeft: 10,
marginRight: 10
},
addIcon: {
alignSelf: 'flex-start'
},
habitsListContainer: {
backgroundColor: 'green',
flex: 10,
flexDirection: 'row'
},
addHabitContainer: {
padding: 20,
flex: 1,
justifyContent: 'center',
},
habit: {
fontSize: 18
},
addBtn: {
fontSize: 16
},
flatlist: {
paddingLeft: 10,
flexDirection: 'row',
height: 60,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
overflow: 'hidden',
borderLeftWidth: 1,
borderTopWidth: 1,
borderBottomWidth: 1
},
streak: {
width: 58,
borderTopLeftRadius: 45,
borderBottomLeftRadius: 45,
height: 80,
backgroundColor: '#E0EEEE',
position: 'relative',
marginLeft: 'auto',
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
},
timeTitle: {
color: '#007aff',
marginBottom: 10
},
});