-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
89 lines (86 loc) · 2.79 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
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { StatusBar } from "expo-status-bar";
import { useEffect, useState } from "react";
import BookParking from "./app/screens/book-parking";
import LoginScreen from "./app/screens/login";
import SelectParking from "./app/screens/select-parking";
import { atomWithStorage, createJSONStorage } from "jotai/utils";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useAtom } from "jotai";
import ParkingSpots from "./app/screens/parking-spots";
import { Button } from "react-native";
import ParkingHistory from "./app/screens/parking-history";
import HomeScreen from "./app/screens/home";
const Stack = createNativeStackNavigator();
export default function App() {
const [user, setUser] = useState(null);
useEffect(() => {
(async () => {
try {
const data = await AsyncStorage.getItem("user");
if (data === null) return;
setUser(data);
} catch (e) {
console.log(e);
}
})();
}, []);
return (
<>
<StatusBar style="auto" />
<NavigationContainer>
<Stack.Navigator>
{user === null ? (
<>
<Stack.Screen name="Home">
{(props) => <HomeScreen {...props} />}
</Stack.Screen>
<Stack.Screen name="Login">
{(props) => <LoginScreen {...props} setUser={setUser} />}
</Stack.Screen>
</>
) : (
<>
<Stack.Screen
name="SelectParking"
options={{
title: "Select Parking",
headerBackVisible: false,
headerRight: () => (
<Button
title="Logout"
onPress={() => {
setUser(null);
AsyncStorage.removeItem("user");
}}
/>
),
}}
component={SelectParking}
/>
<Stack.Screen
name="BookParking"
options={{
title: "Book Parking",
}}
initialParams={{ user }}
component={BookParking}
/>
<Stack.Screen
name="ParkingSpots"
options={{ title: "Parking Spots" }}
component={ParkingSpots}
/>
<Stack.Screen
name="ParkingHistory"
options={{ title: "Parking History" }}
component={ParkingHistory}
/>
</>
)}
</Stack.Navigator>
</NavigationContainer>
</>
);
}