-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
149 lines (114 loc) · 3.32 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
import { StatusBar } from 'expo-status-bar';
import React, {useState} from 'react';
import { Keyboard, TouchableOpacity, KeyboardAvoidingView, StyleSheet, Text, View, TextInput } from 'react-native';
import Tasks from './components/Tasks';
import DateTimePicker from '@react-native-community/datetimepicker';
import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
export default function App() {
{/*Date and Time Picker*/}
const [date, setDate] = useState(new Date());
const [mode, setMode] = useState('date');
const [showDate, setShowDate] = useState('Empty');
const onDateChange = (event, selectedDate) => {
const currentDate = selectedDate || date;
setShowDate(Platform.OS === 'ios');
setDate(currentDate);
let tempDate = new Date(currentDate);
let fDate = tempDate.getDate() + '/' + (tempDate.getMonth()+1) + '/' + tempDate.getFullYear();
let fTime= 'Hours: ' + tempDate.getHours() + '| Minutes ' + tempDate.getMinutes();
}
const showMode = (currentMode) => {
setShowDate(true);
setMode(currentMode);
}
{/* Task Handler */}
const [task, setTask] = useState();
const [taskItems, setTaskItems] = useState([]);
const handleAddTask = () => {
Keyboard.dismiss();
setTaskItems([...taskItems, task])
setTask(null);
}
const completeTask = (index) => {
let itemsCopy = [...taskItems];
itemsCopy.splice(index, 1);
setTaskItems(itemsCopy);
}
return (
<View style={styles.container}>
{/* Todays tasks */}
<View style={styles.tasksWrapper}>
<Text style={styles.sectionTitle}>Todays Tasks</Text>
<View style={styles.items}>
{/* This is where the items will go*/}
{
taskItems.map((item, index)=>{
return (
<TouchableOpacity onPress={() => completeTask(index)}>
<Tasks text={item} />
</TouchableOpacity>
)
})
}
</View>
</View>
{/* Write a task */}
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
style={styles.writeTaskWrapper}
>
<TextInput style={styles.input} placeholder={'Write a task'} value={task} onChangeText={text => setTask(text)} />
<TouchableOpacity onPress={() => handleAddTask()} >
<View style={styles.addWrapper}>
<Text style={styles.addText}>+</Text>
</View>
</TouchableOpacity>
</KeyboardAvoidingView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#E8EAED',
},
tasksWrapper: {
paddingTop: 80,
paddingHorizontal: 20,
},
sectionTitle: {
fontSize: 24,
fontWeight: 'bold',
},
items: {
marginTop: 20,
},
writeTaskWrapper: {
position: 'absolute',
bottom: 60,
width: '100%',
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
},
input: {
padding: 15,
width: 250,
borderRadius: 60,
paddingVertical: 15,
paddingHorizontal: 15,
backgroundColor: '#FFF',
borderColor: '#C0C0C0'
},
addWrapper: {
width: 60,
height: 60,
borderRadius: 60,
backgroundColor: '#FFF',
justifyContent: 'center',
alignItems: 'center',
borderColor: '#C0C0C0',
borderWidth: 1,
},
addText: {},
});