-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
133 lines (114 loc) · 2.66 KB
/
App.tsx
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react';
import {
Button,
FlatList,
StyleSheet,
useColorScheme,
View,
StatusBar,
} from 'react-native';
import {useState} from 'react';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import GoalItem from './components/GoalItem';
import GoalInput from './components/GoalInput';
function App(): React.JSX.Element {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
interface CourseGoalInterface {
goal: string;
id: string;
}
const [modalIsVisible, setModalIsVisible] = useState<Boolean>(false);
const [courseGoals, setCourseGoals] = useState<CourseGoalInterface[]>([]);
function startAddGoalHandler() {
setModalIsVisible(true);
}
function addGoalHandler(enteredGoalText: string) {
setCourseGoals([
...courseGoals,
{goal: enteredGoalText, id: Math.random().toString()},
]);
endAddGoalHandler();
}
function endAddGoalHandler() {
setModalIsVisible(false);
}
function deleteGoalHandler(id: string) {
const filteredItem = courseGoals.filter(
(goal: CourseGoalInterface) => goal.id !== id,
);
setCourseGoals(filteredItem);
}
return (
<View style={styles.appContainer}>
<Button
title="Add New Goal"
color="#a065ec"
onPress={startAddGoalHandler}></Button>
{modalIsVisible && (
<GoalInput
onCancel={endAddGoalHandler}
onAddGoal={addGoalHandler}
visible={modalIsVisible}
/>
)}
<View style={styles.goalsContainer}>
<FlatList
data={courseGoals}
renderItem={item => {
return (
<GoalItem obj={item.item} onDeleteItem={deleteGoalHandler} />
);
}}
keyExtractor={(item, index) => item.id}
/>
</View>
</View>
);
}
const styles = StyleSheet.create({
appContainer: {
flex: 1,
paddingTop: 50,
paddingHorizontal: 16,
backgroundColor: '#1e085a',
},
inputContainer: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
borderBottomWidth: 1,
marginBottom: 20,
borderBlockColor: '#cccccc',
},
textInput: {
borderWidth: 1,
borderColor: '#cccccc',
width: '70%',
marginRight: 8,
padding: 8,
},
goalsContainer: {
marginTop: 8,
flex: 8,
},
goalItems: {
marginBottom: 8,
padding: 8,
borderRadius: 8,
backgroundColor: '#5e0acc',
color: 'white',
},
goalText: {
color: 'white',
},
});
export default App;