diff --git a/src/Components/Drawer/DrawerScreenSettings/CustomDrawerContent/CustomDrawerContent.tsx b/src/Components/Drawer/DrawerScreenSettings/CustomDrawerContent/CustomDrawerContent.tsx index 3838dfd..4d3c13c 100644 --- a/src/Components/Drawer/DrawerScreenSettings/CustomDrawerContent/CustomDrawerContent.tsx +++ b/src/Components/Drawer/DrawerScreenSettings/CustomDrawerContent/CustomDrawerContent.tsx @@ -14,98 +14,136 @@ import SignupIcon from "../../../Icons/SignupIcon/SignupIcon"; import UserIcon from "../../../Icons/UserIcon/UserIcon"; import AppIcon from "../../../Icons/AppIcon/AppIcon"; import LogoutIcon from "../../../Icons/LogoutIcon/LogoutIcon"; +import { useSelector } from "react-redux"; +import { RootState } from "../../../../Features/Redux/Store/Store"; export default function CustomDrawerContent(props: {}) { const navigation = useNavigation(); const width = 224; - return ( - - - - - Clip Notes - - - - { - navigation.navigate("Home"); - }} - > - - Home - - - { - navigation.navigate("New Note"); - }} - > - - - New Note - - - - { - navigation.navigate("Login"); - }} - > - - Login - - - { - navigation.navigate("User Info"); - }} - > - - - User Info - - - - { - navigation.navigate("Register"); - }} - > - - - Register - - - - { - navigation.navigate("Register"); - }} - > - - - Log Out - - - - + const logged_in = useSelector((state: RootState) => state.logged_in.value); + const logged_in_user = useSelector( + (state: RootState) => state.logged_in_user.value ); + if (logged_in) { + return ( + + + + + Clip Notes + + + + Logged in as {logged_in_user.username} + + { + navigation.navigate("Home"); + }} + > + + + Home + + + + { + navigation.navigate("New Note"); + }} + > + + + New Note + + + { + navigation.navigate("User Info"); + }} + > + + + User Info + + + { + navigation.navigate("Register"); + }} + > + + + Log Out + + + + ); + } else { + return ( + + + + + Clip Notes + + + + { + navigation.navigate("Home"); + }} + > + + + Home + + + { + navigation.navigate("Login"); + }} + > + + + Login + + + { + navigation.navigate("Register"); + }} + > + + + Register + + + + ); + } } diff --git a/src/Features/Redux/Store/LoginSlice.tsx b/src/Features/Redux/Store/LoginSlice.tsx deleted file mode 100644 index c86b20b..0000000 --- a/src/Features/Redux/Store/LoginSlice.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { createSlice } from "@reduxjs/toolkit"; - -export const LoginSlice = createSlice({ - name: "Login", - initialState: { - value: false, - }, - reducers: { - SetLoggedIn: (state) => { - state.value = !state.value; - }, - SetLoggedOut: (state) => { - state.value = !state.value; - }, - }, -}); - -// Action creators are generated for each case reducer function -export const { SetLoggedIn, SetLoggedOut } = LoginSlice.actions; - -export default LoginSlice.reducer; diff --git a/src/Routes/Login/Login.tsx b/src/Routes/Login/Login.tsx index b88bd00..90a8998 100644 --- a/src/Routes/Login/Login.tsx +++ b/src/Routes/Login/Login.tsx @@ -16,7 +16,7 @@ import { } from "@react-navigation/native"; import { useDispatch } from "react-redux"; import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice"; -import { SetLoggedIn } from "../../Features/Redux/Store/LoginSlice"; +import { Toggle_Login } from "../../Features/Redux/Slices/LoginSlice/LoginSlice"; import { UserInfo, UserLogin } from "../../Components/Api/Api"; import { RootDrawerParamList } from "../../Interfaces/Interfaces"; @@ -77,7 +77,7 @@ export default function Login() { password: "", }); if (await UserLogin(user)) { - await dispatch(SetLoggedIn()); + await dispatch(Toggle_Login()); await dispatch(SetUser(await UserInfo())); navigation.navigate("Home"); } else {