-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
92 lines (85 loc) · 3.2 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
import "react-native-gesture-handler";
import { StyleSheet, View, TextInput, TouchableOpacity } from "react-native";
import {
Button,
ButtonGroup,
withTheme,
Text,
Icon,
} from "react-native-elements";
import { useState, createContext, useMemo, useEffect } from "react";
import { MainLayout } from "nativeapp/components/layout/mainLayout";
import {
PlayersContext,
EditModeContext,
ActiveGameContext,
} from "nativeapp/components/store/contextStore";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { GameScreen } from "nativeapp/components/screens/gameScreen";
import { PlayersScreen } from "nativeapp/components/screens/playersScreen";
import { HomeScreen } from "nativeapp/components/screens/homeScreen";
import { PrepareGameScreen } from "nativeapp/components/screens/prepareGameScreen";
import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";
import { faCoffee } from "@fortawesome/free-solid-svg-icons";
import storage from "@react-native-async-storage/async-storage";
const Stack = createNativeStackNavigator();
export default function App() {
const [players, setPlayers] = useState([]);
const playersData = useMemo(() => ({ players, setPlayers }), [players]);
const [editMode, setEditMode] = useState(false);
const editModeData = useMemo(() => ({ editMode, setEditMode }), [editMode]);
const [activeGame, setActiveGame] = useState(false);
const activeGameData = useMemo(
() => ({ activeGame, setActiveGame }),
[activeGame]
);
useEffect(() => {
storage.getItem("@players").then((item) => {
const readyData = JSON.parse(item);
if (Array.isArray(readyData)) {
setPlayers(readyData);
}
});
}, []);
useEffect(() => {
console.log(activeGame);
}, [activeGame]);
useEffect(async () => {
await storage.setItem("@players", JSON.stringify(players));
}, [players]);
return (
<PlayersContext.Provider value={playersData}>
<EditModeContext.Provider value={editModeData}>
<ActiveGameContext.Provider value={activeGameData}>
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Game" component={GameScreen} />
<Stack.Screen name="Prepare" component={PrepareGameScreen} />
<Stack.Screen
name="Players"
component={PlayersScreen}
options={{
headerRight: () => (
<Icon
name={editMode ? "check" : "edit"}
type="font-awesome"
color="#f50"
onPress={() =>
setEditMode((prev) => {
return prev ? false : true;
})
}
containerStyle={{ margin: 10 }}
/>
),
}}
/>
</Stack.Navigator>
</NavigationContainer>
</ActiveGameContext.Provider>
</EditModeContext.Provider>
</PlayersContext.Provider>
);
}