mirror of
https://github.com/lemeow125/Ivy-Frontend.git
synced 2025-05-15 19:08:11 +08:00
Polished and removed redundant type interfaces for redux states
This commit is contained in:
parent
3e9a8909a7
commit
6082c572d2
13 changed files with 58 additions and 104 deletions
|
@ -3,16 +3,16 @@ import styles from "../../../styles";
|
|||
import ColoredCube from "../../ColoredCube/ColoredCube";
|
||||
import StatsIcon from "../../Icons/StatsIcon/StatsIcon";
|
||||
import { useSelector } from "react-redux";
|
||||
import { SessionTransactions } from "../../../Interfaces/Interfaces";
|
||||
import { RootState } from "../../../Plugins/Redux/Store/Store";
|
||||
|
||||
export interface props {}
|
||||
|
||||
export default function SessionStatsWidget() {
|
||||
const session_added = useSelector(
|
||||
(state: SessionTransactions) => state.session_transactions.added
|
||||
(state: RootState) => state.session_transactions.added
|
||||
);
|
||||
const session_removed = useSelector(
|
||||
(state: SessionTransactions) => state.session_transactions.removed
|
||||
(state: RootState) => state.session_transactions.removed
|
||||
);
|
||||
return (
|
||||
<div
|
||||
|
|
|
@ -2,13 +2,12 @@ import { useSelector } from "react-redux";
|
|||
import { Button } from "@mui/material";
|
||||
import styles from "../../styles";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { LoggedInUserState } from "../../Interfaces/Interfaces";
|
||||
import { LoginState } from "../../Interfaces/Interfaces";
|
||||
import { RootState } from "../../Plugins/Redux/Store/Store";
|
||||
|
||||
export default function Login() {
|
||||
const logged_in = useSelector((state: LoginState) => state.logged_in.value);
|
||||
const logged_in = useSelector((state: RootState) => state.logged_in.value);
|
||||
const logged_in_user = useSelector(
|
||||
(state: LoggedInUserState) => state.logged_in_user.value
|
||||
(state: RootState) => state.logged_in_user.value
|
||||
);
|
||||
const navigate = useNavigate();
|
||||
if (logged_in) {
|
||||
|
|
|
@ -2,14 +2,14 @@ import * as React from "react";
|
|||
import { Navigate } from "react-router-dom";
|
||||
|
||||
import { useSelector } from "react-redux";
|
||||
import { LoginState, OldSessionState } from "../../Interfaces/Interfaces";
|
||||
import { RootState } from "../../Plugins/Redux/Store/Store";
|
||||
|
||||
export interface props {}
|
||||
|
||||
export default function LoginChecker() {
|
||||
const logged_in = useSelector((state: LoginState) => state.logged_in.value);
|
||||
const logged_in = useSelector((state: RootState) => state.logged_in.value);
|
||||
const old_session_checked = useSelector(
|
||||
(state: OldSessionState) => state.old_session_checked.value
|
||||
(state: RootState) => state.old_session_checked.value
|
||||
);
|
||||
if (!logged_in && !old_session_checked) {
|
||||
} else if (!logged_in && old_session_checked) {
|
||||
|
|
|
@ -1,30 +1,32 @@
|
|||
import * as React from "react";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useCallback } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { UserInfo } from "../Api/Api";
|
||||
import { toggle_login } from "../../Features/Redux/Slices/Login/LoginSlice";
|
||||
import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice";
|
||||
import { LoginState } from "../../Interfaces/Interfaces";
|
||||
import { set_checked } from "../../Features/Redux/Slices/OldSession/OldSessionSlice";
|
||||
import { RootState } from "../../Plugins/Redux/Store/Store";
|
||||
export default function PreviousSessionChecker() {
|
||||
const dispatch = useDispatch();
|
||||
const logged_in = useSelector((state: LoginState) => state.logged_in.value);
|
||||
const logged_in = useSelector((state: RootState) => state.logged_in.value);
|
||||
// Function to check for previous login session
|
||||
useEffect(() => {
|
||||
async function check() {
|
||||
if (await UserInfo()) {
|
||||
if (logged_in !== true) {
|
||||
console.log("Previous session found. Restoring");
|
||||
await dispatch(toggle_login());
|
||||
await dispatch(SetUser(await UserInfo()));
|
||||
}
|
||||
} else {
|
||||
console.log("No old session found");
|
||||
localStorage.removeItem("token");
|
||||
const check = useCallback(async () => {
|
||||
if (await UserInfo()) {
|
||||
if (logged_in !== true) {
|
||||
console.log("Previous session found. Restoring");
|
||||
await dispatch(toggle_login());
|
||||
await dispatch(SetUser(await UserInfo()));
|
||||
}
|
||||
await dispatch(set_checked());
|
||||
} else {
|
||||
console.log("No old session found");
|
||||
localStorage.removeItem("token");
|
||||
}
|
||||
check();
|
||||
}, []);
|
||||
await dispatch(set_checked());
|
||||
}, [dispatch, logged_in]);
|
||||
useEffect(() => {
|
||||
if (!logged_in) {
|
||||
check();
|
||||
}
|
||||
}, [check, logged_in]);
|
||||
return <div />;
|
||||
}
|
||||
|
|
|
@ -10,15 +10,11 @@ import InventoryIcon from "../Icons/InventoryIcon/InventoryIcon";
|
|||
import LogsIcon from "../Icons/LogsIcon/LogsIcon";
|
||||
import LogoutIcon from "../Icons/LogoutIcon/LogoutIcon";
|
||||
import TodayIcon from "../Icons/TodayIcon/TodayIcon";
|
||||
import { RootState } from "../../Plugins/Redux/Store/Store";
|
||||
|
||||
export interface state {
|
||||
logged_in: {
|
||||
value: boolean;
|
||||
};
|
||||
}
|
||||
export default function Sidebar() {
|
||||
const navigate = useNavigate();
|
||||
const logged_in = useSelector((state: state) => state.logged_in.value);
|
||||
const logged_in = useSelector((state: RootState) => state.logged_in.value);
|
||||
function LogoutButton() {
|
||||
if (!logged_in) {
|
||||
return <div />;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue