This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
114 lines (98 loc) · 2.89 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
/* eslint-disable react/display-name */
import * as React from "react";
import { AsyncStorage } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { StatusBar } from "expo-status-bar";
import {
Entypo,
Octicons,
Ionicons
} from "react-native-vector-icons";
import store from "./Redux/Store.js";
import { Provider, useDispatch } from "react-redux";
import { importMatches } from "./Redux/Features/matchSlice.js";
import Scout from "./Routes/Scout.js";
import PastMatches from "./Routes/PastMatches.js";
import About from "./Routes/About.js";
// create bottom tab navigation
const Tab = createBottomTabNavigator();
function MyTabs() {
return (
<Tab.Navigator
initialRouteName="Scout"
tabBarOptions={{
activeTintColor: "#E91E63",
}}
>
<Tab.Screen
name="Scout"
component={Scout}
options={{
tabBarLabel: "Scout",
tabBarIcon: ({ color, size }) => <Octicons name="checklist" color={color} size={size} />
}}
/>
<Tab.Screen
name="PastMatches"
component={PastMatches}
options={{
tabBarLabel: "Past Matches",
tabBarIcon: ({ color, size }) => <Entypo name="back-in-time" color={color} size={size} />
}}
/>
<Tab.Screen
name="About"
component={About}
options={{
tabBarLabel: "About",
tabBarIcon: ({ color, size }) => <Ionicons name="ios-information-circle" color={color} size={size} />
}}
/>
</Tab.Navigator>
);
}
// Async
// Storage
// Setter
// ;)
// The ASS handles stuff like setting matches to [] if empty, and syncing AsyncStorage and state.matches
function ASS() {
const dispatch = useDispatch();
(async () => {
const matches = await AsyncStorage.getItem("matches");
if (matches == null) {
// If not found, set empty match data in AsyncStorage.
await AsyncStorage.setItem("matches", "[]");
} else {
// otherwise sync state.matches.matches and AsyncStorage
// remove any null entries
const parsedMatches = JSON.parse(matches);
const filteredMatches = parsedMatches.filter(v => v instanceof Array);
// dispatch filteredMatches to redux matches
dispatch(importMatches(filteredMatches));
// save filteredMatches to AsyncStorage
if (parsedMatches !== filteredMatches) {
await AsyncStorage.setItem("matches", JSON.stringify(filteredMatches));
}
}
})();
// mmmm, look at that empty component return, it just gives me chills O_o
return <></>;
}
export default function App() {
// make store global bc I want to see the data pls
window.natsumi = store;
// shut up console.warn
// console.warn = () => {}
return (
<Provider store={store}>
{/** ASS must be inside the Provider to dispatch importMatches(), so I made it into a component. */}
<ASS/>
<NavigationContainer>
<MyTabs/>
</NavigationContainer>
<StatusBar style="dark"/>
</Provider>
);
}