-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.js
104 lines (102 loc) · 3.6 KB
/
Home.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
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import AllEntries from "./AllEntries";
import OverLimitEntries from "./OverLimitEntries";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import { View, Text, StyleSheet } from "react-native";
import React, { useEffect, useState } from "react";
import { Ionicons } from "@expo/vector-icons";
import { firestore } from "./Firebase/firebase-setup";
import PressableButton from "./components/PressableButton";
import { styles } from "./components/Styles";
import { collection, onSnapshot } from "firebase/firestore";
import { deleteFromDB, writeToDB } from "./Firebase/firestoreHelper";
const Tab = createBottomTabNavigator();
// const entries = [
// { calories: 300, description: "lunch" },
// { calories: 600, description: "snack" },
// ];
export default function Home({ navigation }) {
useEffect(() => {
const unsubscribe = onSnapshot(
collection(firestore, "entries"),
(querySnapshot) => {
if (querySnapshot.empty) {
setEntries([]);
} else {
let entriesFromDB = [];
querySnapshot.docs.forEach((snapDoc) => {
entriesFromDB.push({ ...snapDoc.data(), id: snapDoc.id });
});
console.log(entriesFromDB);
setEntries(entriesFromDB);
}
}
);
// this is a cleanup function that will be called automatically when the component is unmounted
return () => {
unsubscribe();
};
}, []);
const [entries, setEntries] = useState([]);
console.log(entries);
function entryPressed(pressedEntry) {
// console.log("pressed ", pressedId);
navigation.navigate("EditEntry", { entryItem: pressedEntry });
}
return (
<Tab.Navigator
// tabBarOptions={{ tabBarBackground: "#303f9f" }}
screenOptions={{
// tabBarBackground: "#303f9f",
headerStyle: { backgroundColor: "#303f9f" },
headerTintColor: "#eee",
headerTitleStyle: { fontSize: 20 },
headerRight: () => (
<PressableButton
buttonPressed={() => navigation.navigate("AddAnEntry")}
pressedStyle={styles.pressedStyle}
customizedStyle={styles.addButton}
>
{/* ERROR TypeError: navigation.navigate is not a function. (In 'navigation.navigate("AddAnEntry")', 'navigation.navigate' is undefined) */}
<Ionicons name="add" size={30} style={{ color: "#eee" }} />
</PressableButton>
),
tabBarActiveBackgroundColor: "#303f9f",
tabBarInactiveBackgroundColor: "#303f9f",
tabBarActiveTintColor: "#eee",
tabBarActiveTintColor: "#ffeb3b",
}}
>
<Tab.Screen
name="AllEntries"
// component={AllEntries}
children={() => (
<AllEntries navigation={navigation} entries={entries} />
)}
options={{
// headerShown: false,
tabBarLabel: "All Entries",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="home" color={color} size={size} />
),
}}
/>
<Tab.Screen
name="OverLimitEntries"
// component={OverLimitEntries}
children={() => (
<OverLimitEntries navigation={navigation} entries={entries} />
)}
options={{
// headerShown: false,
tabBarLabel: "Over Limit Entries",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="bell" color={color} size={size} />
),
}}
/>
{/* console.log(firestore); */}
</Tab.Navigator>
);
// </View>
}