-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
85 lines (77 loc) · 2.49 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
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
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { View, Text } from 'react-native';
import { Recipe } from './src/types/recipe';
import { useState, useEffect } from 'react';
import { User } from 'firebase/auth';
import { AuthService } from './src/utils/auth';
import HomeScreen from './src/screens/HomeScreen';
import AddRecipeScreen from './src/screens/AddRecipeScreen';
import RecipeListScreen from './src/screens/RecipeListScreen';
import RecipeDetailScreen from './src/screens/RecipeDetailScreen';
import EditRecipeScreen from './src/screens/EditRecipeScreen';
import AuthScreen from './src/screens/AuthScreen';
export type RootStackParamList = {
Authentication: undefined;
Home: undefined;
AddRecipe: undefined;
RecipeList: undefined;
RecipeDetail: { recipeId: string };
EditRecipe: { recipe: Recipe };
};
const Stack = createNativeStackNavigator<RootStackParamList>();
export default function App() {
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const unsubscribe = AuthService.onAuthStateChanged((user) => {
setUser(user);
setLoading(false);
});
return unsubscribe;
}, []);
if (loading) {
return <View><Text>Loading...</Text></View>;
}
return (
<NavigationContainer>
<Stack.Navigator>
{!user ? (
<Stack.Screen
name="Authentication"
component={AuthScreen}
options={{ title: 'Sign In' }}
/>
) : (
<>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ title: 'Recipe Saver' }}
/>
<Stack.Screen
name="AddRecipe"
component={AddRecipeScreen}
options={{ title: 'Add New Recipe' }}
/>
<Stack.Screen
name="RecipeList"
component={RecipeListScreen}
options={{ title: 'My Recipes' }}
/>
<Stack.Screen
name="RecipeDetail"
component={RecipeDetailScreen}
options={{ title: 'Recipe Details' }}
/>
<Stack.Screen
name="EditRecipe"
component={EditRecipeScreen}
options={{ title: 'Edit Recipe' }}
/>
</>
)}
</Stack.Navigator>
</NavigationContainer>
);
}