diff --git a/ui2/src/app/App.tsx b/ui2/src/app/App.tsx index da866c9cb..f263cf405 100644 --- a/ui2/src/app/App.tsx +++ b/ui2/src/app/App.tsx @@ -1,13 +1,15 @@ +import {useEffect} from "react" import "@mantine/core/styles.css" import {AppShell} from "@mantine/core" -import {Outlet} from "react-router-dom" +import {Outlet, useNavigate} from "react-router-dom" import {useSelector} from "react-redux" import NavBar from "@/components/NavBar" import Header from "@/components/Header/Header" import { selectCurrentUserError, - selectCurrentUserStatus + selectCurrentUserStatus, + selectCurrentUser } from "@/slices/currentUser" import "./App.css" @@ -15,14 +17,22 @@ import {selectNavBarWidth} from "@/slices/navBar" import Uploader from "@/components/Uploader" function App() { + const navigate = useNavigate() const status = useSelector(selectCurrentUserStatus) const error = useSelector(selectCurrentUserError) const navBarWidth = useSelector(selectNavBarWidth) + const user = useSelector(selectCurrentUser) if (status == "failed") { return <>{error} } + useEffect(() => { + if (status == "succeeded" && user) { + navigate(`/home/${user.home_folder_id}`) + } + }, [status]) + return ( <> state.currentUser.data -export const selectCurrentUserStatus = (state: any) => state.currentUser.status -export const selectCurrentUserError = (state: any) => state.currentUser.error +export const selectCurrentUser = (state: any): User => + state.currentUser.data as User +export const selectCurrentUserStatus = (state: any): SliceStateStatus => + state.currentUser.status as SliceStateStatus +export const selectCurrentUserError = (state: any): string => + state.currentUser.error as string