mirror of
https://github.com/lemeow125/Reactnative-notesapp.git
synced 2024-11-16 22:19:26 +08:00
Polish Redux Features
This commit is contained in:
parent
b8e1cb6b63
commit
837299bcc0
5 changed files with 54 additions and 11 deletions
|
@ -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;
|
||||
|
|
17
src/Features/Redux/Slices/OldSession/OldSessionSlice.tsx
Normal file
17
src/Features/Redux/Slices/OldSession/OldSessionSlice.tsx
Normal file
|
@ -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;
|
21
src/Features/Redux/Store/LoginSlice.tsx
Normal file
21
src/Features/Redux/Store/LoginSlice.tsx
Normal file
|
@ -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;
|
|
@ -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<typeof store.getState>;
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
Loading…
Reference in a new issue