-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from arkajyotiadhikary/dev-1
Add private routes for React Native client
- Loading branch information
Showing
12 changed files
with
193 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,13 @@ | ||
import React from "react"; | ||
|
||
// navigaton import | ||
import { NavigationContainer } from "@react-navigation/native"; | ||
import { createStackNavigator } from "@react-navigation/stack"; | ||
const stack = createStackNavigator<RootStackNavigationProp>(); | ||
|
||
// state store | ||
import { Provider } from "react-redux"; | ||
import { store } from "./store"; | ||
|
||
// screens | ||
import Home from "./screens/Home.screen"; | ||
import Auth from "./screens/Auth.screen"; | ||
import PlayerScreen from "./screens/Player.screen"; | ||
import Search from "./screens/Search.screen"; | ||
import { RootStackNavigationProp } from "../types"; | ||
import Router from "./routes/router"; | ||
|
||
export default function App() { | ||
return ( | ||
<Provider store={store}> | ||
<NavigationContainer> | ||
<stack.Navigator | ||
initialRouteName="Home" | ||
screenOptions={{ | ||
headerShown: false, | ||
}} | ||
> | ||
<stack.Screen name="Home" component={Home} /> | ||
<stack.Screen name="Auth" component={Auth} /> | ||
<stack.Screen | ||
name="PlayerScreen" | ||
component={PlayerScreen} | ||
/> | ||
<stack.Screen name="Search" component={Search} /> | ||
</stack.Navigator> | ||
</NavigationContainer> | ||
<Router /> | ||
</Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { createContext, useContext, useState } from "react"; | ||
|
||
interface AuthContextData { | ||
isAuthenticated: boolean; | ||
setIsAuthenticated: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
export const AuthContext = createContext<AuthContextData | null>(null); | ||
|
||
interface AuthProviderProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => { | ||
const [isAuthenticated, setIsAuthenticated] = useState(false); | ||
|
||
const value: AuthContextData = { isAuthenticated, setIsAuthenticated }; | ||
|
||
return ( | ||
<AuthContext.Provider value={value}>{children}</AuthContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { PayloadAction, createSlice } from "@reduxjs/toolkit"; | ||
|
||
interface User { | ||
isAuthenticated: boolean; | ||
} | ||
|
||
const initUserState: User = { | ||
isAuthenticated: false, | ||
}; | ||
|
||
export const userSlice = createSlice({ | ||
name: "user", | ||
initialState: initUserState, | ||
reducers: { | ||
setCurrentUser(state, action: PayloadAction<User>) { | ||
state.isAuthenticated = action.payload.isAuthenticated; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setCurrentUser } = userSlice.actions; | ||
export const userReducer = userSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NavigationContainer } from "@react-navigation/native"; | ||
import { AppStack, AuthStack } from "../stacks/mAuth.stack"; | ||
import { useSelector } from "react-redux"; | ||
import { RootState } from "../store"; | ||
|
||
const Router = () => { | ||
const userState = useSelector((state: RootState) => state.userReducer); | ||
return ( | ||
<NavigationContainer> | ||
{userState.isAuthenticated ? <AppStack /> : <AuthStack />} | ||
</NavigationContainer> | ||
); | ||
}; | ||
|
||
export default Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createStackNavigator } from "@react-navigation/stack"; | ||
import { RootStackParamList } from "../../types"; | ||
import Home from "../screens/Home.screen"; | ||
import Auth from "../screens/Auth.screen"; | ||
|
||
const Stack = createStackNavigator<RootStackParamList>(); | ||
|
||
export const AppStack = () => { | ||
return ( | ||
<Stack.Navigator | ||
screenOptions={{ | ||
headerShown: false, | ||
}} | ||
> | ||
<Stack.Screen name="Home" component={Home} /> | ||
</Stack.Navigator> | ||
); | ||
}; | ||
|
||
export const AuthStack = () => { | ||
return ( | ||
<Stack.Navigator | ||
screenOptions={{ | ||
headerShown: false, | ||
}} | ||
> | ||
<Stack.Screen name="Auth" component={Auth} /> | ||
</Stack.Navigator> | ||
); | ||
}; |
Oops, something went wrong.