-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
228 lines (223 loc) · 5.27 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import { StatusBar } from "expo-status-bar";
import { useEffect, useState } from "react";
import {
Button,
ScrollView,
StyleSheet,
Text,
View,
Image,
Pressable,
} from "react-native";
import TodoInput from "./components/TodoInput";
import TodoOutput from "./components/TodoOutput";
export default function App() {
const [takeInput, setTakeInput] = useState(false);
const [todos, setTodos] = useState([]);
const [completed, setCompleted] = useState(0);
const [pending, setPending] = useState(0);
const addTodoToList = (todo) => {
const todoObj = {
key: todos.length,
text: todo,
done: false,
};
setTodos(() => {
return [...todos, todoObj];
});
setCompleted(() => {
const completedArray = todos.filter((todo) => {
return todo.done == true;
});
return completedArray.length;
});
setPending(() => {
const completedArray = todos.filter((todo) => {
return todo.done == true;
});
return todos.length - completedArray.length;
});
};
const onDone = (key, done) => {
todos[key].done = done;
setTodos(() => [...todos]);
setCompleted(() => {
const completedArray = todos.filter((todo) => {
return todo.done == true;
});
console.log(completedArray);
return completedArray.length;
});
setPending(() => {
const completedArray = todos.filter((todo) => {
return todo.done == true;
});
return todos.length - completedArray.length;
});
};
return (
<View style={styles.container}>
<StatusBar style="light" />
<View
style={{
marginTop: "5%",
alignItems: "center",
flexDirection: "row",
justifyContent: "space-evenly",
alignContent: "flex-start",
marginBottom: "2%",
}}
>
<View style={styles.count}>
<Text style={styles.h1}> {todos.length} </Text>
</View>
<View style={styles.h1C}>
<Text style={styles.h1}> ₸⭕☑⭕</Text>
</View>
<View style={takeInput ? styles.addPress : styles.addC}>
<Pressable
style={{
alignContent: "center",
alignItems: "center",
justifyContent: "center",
}}
onPress={() => setTakeInput(true)}
>
<Text style={styles.add}>➕</Text>
</Pressable>
</View>
</View>
<View
keyboardShouldPersistTaps="always"
style={styles.sv}
contentContainerStyle={{
alignContent: "center",
justifyContent: "center",
}}
>
<TodoInput
takeInput={takeInput}
setTakeInput={setTakeInput}
addTodoToList={addTodoToList}
/>
<View
style={{
height: 500,
backgroundColor: "#1c1c1c",
borderRadius: "25%",
marginLeft: "2.5%",
marginRight: "2.5%",
}}
>
<TodoOutput onDone={onDone} todos={todos} />
</View>
<View
style={{
marginTop: "5%",
flexDirection: "row",
justifyContent: "space-evenly",
}}
>
<View style={styles.completedC}>
<Text style={styles.completed}>Completed:{completed}</Text>
</View>
<View style={styles.notcompletedC}>
<Text style={styles.notcompleted}>Pending:{pending}</Text>
</View>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "black",
},
sv: {
flex: 1,
backgroundColor: "black",
},
h1: {
alignItems: "center",
color: "white",
fontSize: 30,
fontWeight: "700",
padding: "1%",
},
h2: {
color: "white",
fontSize: 20,
margin: "1%",
fontWeight: "400",
padding: "1%",
},
h1C: {
marginTop: "5%",
borderRadius: 200,
padding: "1%",
backgroundColor: "#353535a3",
},
count: {
marginTop: "5%",
borderRadius: 25,
padding: "1%",
paddingLeft: "1.5%",
paddingRight: "1.5%",
backgroundColor: "#353535a3",
},
add: {
alignItems: "center",
justifyContent: "center",
fontSize: 30,
padding: "1.5%",
},
addPress: {
marginTop: "5%",
borderRadius: 25,
alignContent: "center",
paddingLeft: "0.5%",
paddingRight: "0.5%",
backgroundColor: "#00F81D8E",
},
addC: {
marginTop: "5%",
borderRadius: 25,
alignContent: "center",
paddingLeft: "0.5%",
paddingRight: "0.5%",
backgroundColor: "rgba(255,255,255,1)",
},
completed: {
fontSize: 20,
alignItems: "center",
justifyContent: "center",
color: "white",
},
completedC: {
width: 120,
padding: "2%",
justifyContent: "center",
alignItems: "center",
borderRadius: "25%",
borderColor: "#00570A",
borderWidth: "1%",
backgroundColor: "#003306",
},
notcompleted: {
fontSize: 20,
alignItems: "center",
justifyContent: "center",
color: "white",
},
notcompletedC: {
width: 120,
padding: "2%",
justifyContent: "center",
alignItems: "center",
borderRadius: "25%",
borderColor: "#872900",
borderWidth: "1%",
backgroundColor: "#4F1A01",
},
});