-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
54 lines (47 loc) · 1.34 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
import { StatusBar } from "expo-status-bar";
import { useState } from "react";
import { Button, FlatList, StyleSheet, View } from "react-native";
import GoalCard from "./components/GoalCard";
import GoalInput, { Goal } from "./components/GoalInput";
export default function App() {
const [goals, setGoals] = useState<Goal[]>([]);
const [modalVisible, setModalVisible] = useState<boolean>(false);
const onAddGoal = (goal: Goal) => {
setGoals((currentGoals) => [...currentGoals, goal]);
setModalVisible(false);
};
const onRemoveGoal = (flutter: string) => {
setGoals((currentGoals) =>
currentGoals.filter((goal) => goal.flutter !== flutter)
);
};
const onAddGoalPress = () => {
setModalVisible(true);
};
const onCancelGoal = () => {
setModalVisible(false);
};
return (
<View style={styles.screen}>
<StatusBar style="auto" />
<Button title="Add Goal" onPress={onAddGoalPress} />
<GoalInput
onAddGoal={onAddGoal}
onCancel={onCancelGoal}
visible={modalVisible}
/>
<FlatList
keyExtractor={(item, index) => item.flutter}
data={goals}
renderItem={(goal) => (
<GoalCard goal={goal.item} onGoalPress={onRemoveGoal} />
)}
/>
</View>
);
}
const styles = StyleSheet.create({
screen: {
padding: 50,
},
});