From 716bd2f65b2257d4bb41f972506c662cfb91d2c1 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Wed, 12 Jun 2024 17:50:51 -0300 Subject: [PATCH] Refactor code to handle artifacts in chat messages and improve error handling --- src/frontend/src/App.tsx | 1 - .../src/components/headerComponent/index.tsx | 5 +++-- src/frontend/src/contexts/authContext.tsx | 12 +++++++----- src/frontend/src/pages/LoginPage/index.tsx | 3 +-- .../components/ProfilePictureForm/index.tsx | 1 - 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index 4a60f453f..04d48103b 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -80,7 +80,6 @@ export default function App() { login(user["access_token"]); setUserData(user); setAutoLogin(true); - setLoading(false); fetchAllData(); } }) diff --git a/src/frontend/src/components/headerComponent/index.tsx b/src/frontend/src/components/headerComponent/index.tsx index 8a2b9a2cf..ef6b8938d 100644 --- a/src/frontend/src/components/headerComponent/index.tsx +++ b/src/frontend/src/components/headerComponent/index.tsx @@ -36,6 +36,7 @@ export default function Header(): JSX.Element { const location = useLocation(); const { logout, autoLogin, isAdmin, userData } = useContext(AuthContext); + const navigate = useNavigate(); const removeFlow = useFlowsManagerStore((store) => store.removeFlow); const hasStore = useStoreStore((state) => state.hasStore); @@ -202,7 +203,7 @@ export default function Header(): JSX.Element { 0, BACKEND_URL.length - 1, )}${BASE_URL_API}files/profile_pictures/${ - userData?.profile_image ?? "Space/046-rocket.png" + userData?.profile_image ?? "Space/046-rocket.svg" }` ?? profileCircle } className="h-7 w-7 shrink-0 focus-visible:outline-0" @@ -220,7 +221,7 @@ export default function Header(): JSX.Element { 0, BACKEND_URL.length - 1, )}${BASE_URL_API}files/profile_pictures/${ - userData?.profile_image + userData?.profile_image ?? "Space/046-rocket.svg" }` ?? profileCircle } className="h-5 w-5 focus-visible:outline-0 " diff --git a/src/frontend/src/contexts/authContext.tsx b/src/frontend/src/contexts/authContext.tsx index 43416f373..fbb7f8f1e 100644 --- a/src/frontend/src/contexts/authContext.tsx +++ b/src/frontend/src/contexts/authContext.tsx @@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom"; import Cookies from "universal-cookie"; import { getLoggedUser, requestLogout } from "../controllers/API"; import useAlertStore from "../stores/alertStore"; +import { useFolderStore } from "../stores/foldersStore"; import { Users } from "../types/api"; import { AuthContextType } from "../types/contexts/auth"; @@ -30,18 +31,19 @@ export function AuthProvider({ children }): React.ReactElement { const navigate = useNavigate(); const cookies = new Cookies(); const [accessToken, setAccessToken] = useState( - cookies.get("access_token_lf") ?? null + cookies.get("access_token_lf") ?? null, ); const [isAuthenticated, setIsAuthenticated] = useState( - !!cookies.get("access_token_lf") + !!cookies.get("access_token_lf"), ); const [isAdmin, setIsAdmin] = useState(false); const [userData, setUserData] = useState(null); const [autoLogin, setAutoLogin] = useState(false); const setLoading = useAlertStore((state) => state.setLoading); const [apiKey, setApiKey] = useState( - cookies.get("apikey_tkn_lflw") + cookies.get("apikey_tkn_lflw"), ); + const getFoldersApi = useFolderStore((state) => state.getFoldersApi); useEffect(() => { const storedAccessToken = cookies.get("access_token_lf"); @@ -59,11 +61,11 @@ export function AuthProvider({ children }): React.ReactElement { function getUser() { getLoggedUser() - .then((user) => { + .then(async (user) => { setUserData(user); - setLoading(false); const isSuperUser = user!.is_superuser; setIsAdmin(isSuperUser); + await getFoldersApi(true); }) .catch((error) => { setLoading(false); diff --git a/src/frontend/src/pages/LoginPage/index.tsx b/src/frontend/src/pages/LoginPage/index.tsx index 2d9ea59c9..826b2a931 100644 --- a/src/frontend/src/pages/LoginPage/index.tsx +++ b/src/frontend/src/pages/LoginPage/index.tsx @@ -20,8 +20,7 @@ export default function LoginPage(): JSX.Element { useState(CONTROL_LOGIN_STATE); const { password, username } = inputState; - const { login, isAuthenticated, setUserData, setIsAdmin } = - useContext(AuthContext); + const { login } = useContext(AuthContext); const navigate = useNavigate(); const setErrorData = useAlertStore((state) => state.setErrorData); diff --git a/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/index.tsx b/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/index.tsx index 908cea255..0536b2b7b 100644 --- a/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/index.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/GeneralPage/components/ProfilePictureForm/index.tsx @@ -47,7 +47,6 @@ const ProfilePictureFormComponent = ({ } return prev; }); - setLoading(false); }); } })