-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
203 lines (190 loc) · 5.45 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
import { StatusBar } from 'expo-status-bar';
import React, {useState, useEffect} from 'react';
import { StyleSheet, Text, SafeAreaView, ScrollView, View, Button, TextInput, DatePickerIOS} from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import * as SQLite from 'expo-sqlite';
const Stack = createNativeStackNavigator();
const styles = StyleSheet.create({
center: {
alignItems: 'center'
},
button: {
backgroundColor: '#dcb8cb',
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
},
bigInput: {
height: 400,
margin: 12,
borderWidth: 1,
padding: 10,
}
})
const db = SQLite.openDatabase('tasks.db')//returns Database object
const App = () => {
db.transaction(tx => {
tx.executeSql('CREATE TABLE IF NOT EXISTS tasks (date TEXT, title TEXT, description TEXT)',
null,
() => {console.log('success1')},
() => {console.log('fail')}
)},
() =>{ console.log('fail')},
() => {console.log('success2')}
)
const[currentDate, setCurrentDate] = useState('');
useEffect(() => {
var date = new Date().getDate(); //Current Date
var month = new Date().getMonth() + 1; //Current Month
var year = new Date().getFullYear(); //Current Year
var hours = new Date().getHours(); //Current Hours
var min = new Date().getMinutes(); //Current Minutes
var sec = new Date().getSeconds(); //Current Seconds
setCurrentDate(
month + '/' + date + '/' + year
+ ' ' + hours + ':' + min + ':' + sec
);
}, [])
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
title: 'Home',
headerStyle: {
backgroundColor:'#0471a6'
},
headerTintColor:'#D5C9DF'
}}
/>
<Stack.Screen name="Add" component={AddScreen}
options={{
title: 'Add',
headerStyle: {
backgroundColor:'#0471a6'
},
headerTintColor:'#D5C9DF'
}}
/>
<Stack.Screen name="Calendar" component={CalendarScreen}
options={{
title: 'Calendar',
headerStyle: {
backgroundColor:'#0471a6'
},
headerTintColor:'#D5C9DF'
}}
/>
<Stack.Screen name="Today" component={TodayScreen}
options={{
title: 'Today',
headerStyle: {
backgroundColor:'#0471a6'
},
headerTintColor:'#D5C9DF'
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
const HomeScreen = ({ navigation }) => {
return (
<View style={[styles.center, {flex: 1}, {backgroundColor: '#CEEAF7'}]}>
<View style={{flex: 1, alignSelf: 'stretch', backgroundColor: '#CEEAF7'}}>
<View style={[styles.button,{justifyContent: 'flex-end'}, {alignSelf: 'flex-end'}]}>
<Button
color="#8e5572"
title="Add a task"
onPress={() =>
navigation.navigate('Add')
}
/>
</View>
</View>
<View style={{flex: 1, alignSelf: 'stretch', backgroundColor: '#CEEAF7'}}>
<Greeting name='Brandon'/>
</View>
<View style={{flex: 1, flexDirection: 'row', alignSelf: 'stretch', justifyContent: 'space-around', backgroundColor: '#CEEAF7'}}>
<View style={[styles.button,{justifyContent: 'flex-end'}, {alignSelf: 'flex-start'}]}>
<Button
color="#8e5572"
title="Calendar"
onPress={() =>
navigation.navigate('Calendar')
}
/>
</View>
<View style={[styles.button,{justifyContent: 'flex-start'}, {alignSelf: 'flex-start'}]}>
<Button
color="#8e5572"
title="Today"
onPress={() =>
navigation.navigate('Today')
}
/>
</View>
</View>
</View>
)
}
const AddScreen = ({ navigation, route }) => {
const [chosenDate, setChosenDate] = useState(new Date());
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
function test(){
console.log('hello')
navigation.navigate('Today')
}
return (
<SafeAreaView style={[{flex: 1}, {backgroundColor: '#CEEAF7'}]}>
<ScrollView>
<DatePickerIOS
date={chosenDate}
onDateChange={setChosenDate}
/>
<TextInput
style={styles.input}
onChangeText={setTitle}
value={title}
placeholder="New Task Title"
/>
<View style={styles.bigInput}>
<TextInput
multiline
numberOfLines={10}
maxLength = {80}
onChange={text => setDescription(text)}
value = {description}
placeholder="Description"
editable
/>
</View>
<Button
onPress={test}
title="Submit"
/>
</ScrollView>
</SafeAreaView>
)
};
const CalendarScreen = ({ navigation, route }) => {
return <Text>Hello this is the calendar screen</Text>;
};
const TodayScreen = ({ navigation, route }) => {
return <Text>Hello this is the today screen</Text>;
};
const Greeting = (props) => {
return (
<View style={styles.center}>
<Text style={{color: '#D5C9DF'}}>Hello {props.name}!</Text>
</View>
);
}
export default App;