-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
73 lines (63 loc) · 1.93 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
import { useState } from 'react';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, TextInput, Button, ScrollView, FlatList } from 'react-native';
import GoalItem from './components/GoalItem';
import { GoalInput } from './components/GoalInput';
export default function App() {
const [enteredGoal, setEnteredGoal] = useState('');
const [courseGoal, setCourseGoal] = useState([]);
const [modalVisible, setModalVisible] = useState(false)
const handleCloseModal = () => {
setModalVisible(false)
}
const handleChangeInput = (enteredText) => {
setEnteredGoal(enteredText)
}
const handleClickAddGoal = () => {
setCourseGoal((prev) => [...prev, { text: enteredGoal, id: Math.random() }])
setEnteredGoal('')
handleCloseModal()
}
const handleDeleteItem = (id) => {
setCourseGoal((prev) => prev.filter((item) => item.id !== id))
}
return (
<>
<StatusBar style='light' />
<View style={styles.appContainer}>
<Button title='Add New Goal' color='#5e0acc' onPress={() => setModalVisible(true)} />
<GoalInput
showModal={modalVisible}
value={enteredGoal}
handleChangeInput={handleChangeInput}
handleClickAddGoal={handleClickAddGoal}
handleCloseModal={handleCloseModal}
/>
<View style={styles.goalsContainer}>
<FlatList
data={courseGoal}
renderItem={(itemData) => {
return <GoalItem id={itemData.item.id} text={itemData.item.text} handleDeleteItem={handleDeleteItem} />
}}
keyExtractor={(item, index) => {
return item.id
}}
>
</FlatList>
</View>
</View>
</>
);
}
const styles = StyleSheet.create({
appContainer: {
flex: 1,
paddingTop: 50,
paddingHorizontal: 16,
// backgroundColor: '#1e085a'
// padding: 50,
},
goalsContainer: {
flex: 5
},
});