diff --git a/src/Features/Redux/Slices/LoginSlice/LoginSlice.tsx b/src/Features/Redux/Slices/LoginSlice/LoginSlice.tsx index 86f4ac5..4cbfa2a 100644 --- a/src/Features/Redux/Slices/LoginSlice/LoginSlice.tsx +++ b/src/Features/Redux/Slices/LoginSlice/LoginSlice.tsx @@ -3,19 +3,16 @@ import { createSlice } from "@reduxjs/toolkit"; export const LoginSlice = createSlice({ name: "Login", initialState: { - logged_in: false, + value: false, }, reducers: { - SetLoggedIn: (state) => { - state.logged_in = !state.logged_in; - }, - SetLoggedOut: (state) => { - state.logged_in = !state.logged_in; + Toggle_Login: (state) => { + state.value = !state.value; }, }, }); // Action creators are generated for each case reducer function -export const { SetLoggedIn, SetLoggedOut } = LoginSlice.actions; +export const { Toggle_Login } = LoginSlice.actions; export default LoginSlice.reducer; diff --git a/src/Features/Redux/Slices/OldSession/OldSessionSlice.tsx b/src/Features/Redux/Slices/OldSession/OldSessionSlice.tsx new file mode 100644 index 0000000..d122a50 --- /dev/null +++ b/src/Features/Redux/Slices/OldSession/OldSessionSlice.tsx @@ -0,0 +1,17 @@ +import { createSlice } from "@reduxjs/toolkit"; + +export const OldSessionSlice = createSlice({ + name: "old_session_checked", + initialState: { + value: false, + }, + reducers: { + set_checked: (state) => { + state.value = !state.value; + }, + }, +}); + +export const { set_checked } = OldSessionSlice.actions; + +export default OldSessionSlice.reducer; diff --git a/src/Features/Redux/Store/LoginSlice.tsx b/src/Features/Redux/Store/LoginSlice.tsx new file mode 100644 index 0000000..c86b20b --- /dev/null +++ b/src/Features/Redux/Store/LoginSlice.tsx @@ -0,0 +1,21 @@ +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/Features/Redux/Store/Store.tsx b/src/Features/Redux/Store/Store.tsx index 063fd36..6da5d11 100644 --- a/src/Features/Redux/Store/Store.tsx +++ b/src/Features/Redux/Store/Store.tsx @@ -1,10 +1,18 @@ import { configureStore } from "@reduxjs/toolkit"; import LoginReducer from "../Slices/LoginSlice/LoginSlice"; import LoggedInUserReucer from "../Slices/LoggedInUserSlice/LoggedInUserSlice"; +import OldSessionReducer from "../Slices/OldSession/OldSessionSlice"; -export default configureStore({ +const store = configureStore({ reducer: { - Login: LoginReducer, - LoggedInUser: LoggedInUserReucer, + logged_in: LoginReducer, + logged_in_user: LoggedInUserReucer, + old_session_checked: OldSessionReducer, }, }); + +export default store; + +// Infer the `RootState` and `AppDispatch` types from the store itself +export type RootState = ReturnType; +export type AppDispatch = typeof store.dispatch; diff --git a/src/Routes/Login/Login.tsx b/src/Routes/Login/Login.tsx index 731b05e..b88bd00 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/Slices/LoginSlice/LoginSlice"; +import { SetLoggedIn } from "../../Features/Redux/Store/LoginSlice"; import { UserInfo, UserLogin } from "../../Components/Api/Api"; import { RootDrawerParamList } from "../../Interfaces/Interfaces";