Polish Redux Features

This commit is contained in:
toledo 2023-04-08 21:27:04 +08:00
parent b8e1cb6b63
commit 837299bcc0
5 changed files with 54 additions and 11 deletions

View file

@ -3,19 +3,16 @@ import { createSlice } from "@reduxjs/toolkit";
export const LoginSlice = createSlice({ export const LoginSlice = createSlice({
name: "Login", name: "Login",
initialState: { initialState: {
logged_in: false, value: false,
}, },
reducers: { reducers: {
SetLoggedIn: (state) => { Toggle_Login: (state) => {
state.logged_in = !state.logged_in; state.value = !state.value;
},
SetLoggedOut: (state) => {
state.logged_in = !state.logged_in;
}, },
}, },
}); });
// Action creators are generated for each case reducer function // 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; export default LoginSlice.reducer;

View 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;

View 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;

View file

@ -1,10 +1,18 @@
import { configureStore } from "@reduxjs/toolkit"; import { configureStore } from "@reduxjs/toolkit";
import LoginReducer from "../Slices/LoginSlice/LoginSlice"; import LoginReducer from "../Slices/LoginSlice/LoginSlice";
import LoggedInUserReucer from "../Slices/LoggedInUserSlice/LoggedInUserSlice"; import LoggedInUserReucer from "../Slices/LoggedInUserSlice/LoggedInUserSlice";
import OldSessionReducer from "../Slices/OldSession/OldSessionSlice";
export default configureStore({ const store = configureStore({
reducer: { reducer: {
Login: LoginReducer, logged_in: LoginReducer,
LoggedInUser: LoggedInUserReucer, 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;

View file

@ -16,7 +16,7 @@ import {
} from "@react-navigation/native"; } from "@react-navigation/native";
import { useDispatch } from "react-redux"; import { useDispatch } from "react-redux";
import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice"; 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 { UserInfo, UserLogin } from "../../Components/Api/Api";
import { RootDrawerParamList } from "../../Interfaces/Interfaces"; import { RootDrawerParamList } from "../../Interfaces/Interfaces";