Skip to content

Commit a76a429

Browse files
committed
feat: Add welcome screen
1 parent b852b90 commit a76a429

File tree

4 files changed

+72
-11
lines changed

4 files changed

+72
-11
lines changed

app/src/constants/screens.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
// File: screens.ts
2-
// Description: This file defines enums for screen and stack names used in the application's navigation structure.
3-
// The `Screens` enum is used to define the names of individual screens.
4-
// The `Stacks` enum is used to define the names of navigation stacks (authenticated and unauthenticated).
5-
// Usage:
6-
// - The `Screens` enum is used in the `UnAuthRoutes` and `AuthRoutes` components to define the routes for various screens.
7-
// - The `Stacks` enum is used in the `AppRoutes` component to define the main navigation stacks for authenticated and unauthenticated users.
8-
91
export enum Screens {
102
SignIn = 'SignIn',
113
SignUp = 'SignUp',
124
ForgotPassword = 'ForgotPassword',
135
ResetPassword = 'ResetPassword',
146
Landing = 'Landing',
157
Home = 'Home',
16-
Profile = 'Profile'
8+
Profile = 'Profile',
9+
Welcome = 'Welcome'
1710
}
1811

1912
export enum Stacks {

app/src/routes/AuthRoutes.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import { createDrawerNavigator } from '@react-navigation/drawer';
66
import { Drawer, Header } from '@src/components';
77
import { Screens } from '@src/constants';
8-
import { Home, Profile } from '@src/screens';
8+
import { Home, Profile, Welcome } from '@src/screens';
99

1010
// Define the parameter types for the AuthRoutes drawer navigator
1111
export type AuthRoutesParams = {
1212
[Screens.Home]: undefined;
1313
[Screens.Profile]: undefined;
14+
[Screens.Welcome]: undefined;
1415
};
1516

1617
// Create a drawer navigator for authenticated routes
@@ -24,10 +25,15 @@ const AuthDrawer = createDrawerNavigator<AuthRoutesParams>();
2425
export const AuthRoutes: React.FC = () => {
2526
return (
2627
<AuthDrawer.Navigator
27-
initialRouteName={Screens.Home}
28+
initialRouteName={Screens.Welcome}
2829
screenOptions={{ header: (props) => <Header {...props} /> }}
2930
drawerContent={(props) => <Drawer {...props} />}
3031
>
32+
<AuthDrawer.Screen
33+
name={Screens.Welcome}
34+
component={Welcome}
35+
options={{ headerShown: false }}
36+
/>
3137
<AuthDrawer.Screen name={Screens.Home} component={Home} />
3238
<AuthDrawer.Screen name={Screens.Profile} component={Profile} />
3339
</AuthDrawer.Navigator>

app/src/screens/Welcome.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useNavigation } from '@react-navigation/native';
2+
import { Button, Text } from '@shadcn/components';
3+
import { H2 } from '@shadcn/components/ui/typography';
4+
import { Screens, Stacks, fireAuth, fireStore } from '@src/constants';
5+
import type { AppNavigation } from '@src/types';
6+
import { Asset } from 'expo-asset';
7+
import { doc, getDoc } from 'firebase/firestore';
8+
import type * as React from 'react';
9+
import { useEffect, useState } from 'react';
10+
import { Image, View } from 'react-native';
11+
12+
export const Welcome: React.FC = () => {
13+
const image = Asset.fromModule(require('../../assets/landing.png')).uri;
14+
const { navigate } = useNavigation<AppNavigation>();
15+
const [hasSeenWelcome, setHasSeenWelcome] = useState<boolean | null>(null);
16+
const [loading, setLoading] = useState<boolean>(true);
17+
const [visited, setVisited] = useState<boolean>(false);
18+
19+
useEffect(() => {
20+
const checkUserInFirestore = async () => {
21+
try {
22+
setLoading(true);
23+
const user = fireAuth.currentUser;
24+
if (!user) return;
25+
const docRef = doc(fireStore, 'users', user.uid);
26+
const docSnap = await getDoc(docRef);
27+
} catch (error) {
28+
console.error(error);
29+
} finally {
30+
setLoading(false);
31+
}
32+
};
33+
checkUserInFirestore();
34+
}, []);
35+
36+
const handleContinue = () => {
37+
navigate(Stacks.Auth, { screen: Screens.Home });
38+
};
39+
40+
return (
41+
<View className='flex-1 flex-col justify-center items-center p-4'>
42+
<Image
43+
source={{ uri: image }}
44+
className='w-[95%] h-auto left-16 aspect-square'
45+
resizeMode='contain'
46+
key={'landing-image'}
47+
/>
48+
<H2 className='text-center mt-4'>Welcome to COGNIKIDS!</H2>
49+
<Button size={'lg'} className='w-full rounded-full mb-2' onPress={handleContinue}>
50+
<Text>Continue session</Text>
51+
</Button>
52+
<Button
53+
size={'lg'}
54+
className='w-full rounded-full'
55+
onPress={() => navigate(Stacks.Auth, { screen: Screens.Home })}
56+
>
57+
<Text>Home</Text>
58+
</Button>
59+
</View>
60+
);
61+
};

app/src/screens/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './Profile';
1010
export * from './ResetPassword';
1111
export * from './SignIn';
1212
export * from './SignUp';
13+
export * from './Welcome';

0 commit comments

Comments
 (0)