Refactor code to handle artifacts in chat messages and improve error handling

This commit is contained in:
cristhianzl 2024-06-12 17:50:51 -03:00
commit 716bd2f65b
5 changed files with 11 additions and 11 deletions

View file

@ -80,7 +80,6 @@ export default function App() {
login(user["access_token"]); login(user["access_token"]);
setUserData(user); setUserData(user);
setAutoLogin(true); setAutoLogin(true);
setLoading(false);
fetchAllData(); fetchAllData();
} }
}) })

View file

@ -36,6 +36,7 @@ export default function Header(): JSX.Element {
const location = useLocation(); const location = useLocation();
const { logout, autoLogin, isAdmin, userData } = useContext(AuthContext); const { logout, autoLogin, isAdmin, userData } = useContext(AuthContext);
const navigate = useNavigate(); const navigate = useNavigate();
const removeFlow = useFlowsManagerStore((store) => store.removeFlow); const removeFlow = useFlowsManagerStore((store) => store.removeFlow);
const hasStore = useStoreStore((state) => state.hasStore); const hasStore = useStoreStore((state) => state.hasStore);
@ -202,7 +203,7 @@ export default function Header(): JSX.Element {
0, 0,
BACKEND_URL.length - 1, BACKEND_URL.length - 1,
)}${BASE_URL_API}files/profile_pictures/${ )}${BASE_URL_API}files/profile_pictures/${
userData?.profile_image ?? "Space/046-rocket.png" userData?.profile_image ?? "Space/046-rocket.svg"
}` ?? profileCircle }` ?? profileCircle
} }
className="h-7 w-7 shrink-0 focus-visible:outline-0" className="h-7 w-7 shrink-0 focus-visible:outline-0"
@ -220,7 +221,7 @@ export default function Header(): JSX.Element {
0, 0,
BACKEND_URL.length - 1, BACKEND_URL.length - 1,
)}${BASE_URL_API}files/profile_pictures/${ )}${BASE_URL_API}files/profile_pictures/${
userData?.profile_image userData?.profile_image ?? "Space/046-rocket.svg"
}` ?? profileCircle }` ?? profileCircle
} }
className="h-5 w-5 focus-visible:outline-0 " className="h-5 w-5 focus-visible:outline-0 "

View file

@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom";
import Cookies from "universal-cookie"; import Cookies from "universal-cookie";
import { getLoggedUser, requestLogout } from "../controllers/API"; import { getLoggedUser, requestLogout } from "../controllers/API";
import useAlertStore from "../stores/alertStore"; import useAlertStore from "../stores/alertStore";
import { useFolderStore } from "../stores/foldersStore";
import { Users } from "../types/api"; import { Users } from "../types/api";
import { AuthContextType } from "../types/contexts/auth"; import { AuthContextType } from "../types/contexts/auth";
@ -30,18 +31,19 @@ export function AuthProvider({ children }): React.ReactElement {
const navigate = useNavigate(); const navigate = useNavigate();
const cookies = new Cookies(); const cookies = new Cookies();
const [accessToken, setAccessToken] = useState<string | null>( const [accessToken, setAccessToken] = useState<string | null>(
cookies.get("access_token_lf") ?? null cookies.get("access_token_lf") ?? null,
); );
const [isAuthenticated, setIsAuthenticated] = useState<boolean>( const [isAuthenticated, setIsAuthenticated] = useState<boolean>(
!!cookies.get("access_token_lf") !!cookies.get("access_token_lf"),
); );
const [isAdmin, setIsAdmin] = useState<boolean>(false); const [isAdmin, setIsAdmin] = useState<boolean>(false);
const [userData, setUserData] = useState<Users | null>(null); const [userData, setUserData] = useState<Users | null>(null);
const [autoLogin, setAutoLogin] = useState<boolean>(false); const [autoLogin, setAutoLogin] = useState<boolean>(false);
const setLoading = useAlertStore((state) => state.setLoading); const setLoading = useAlertStore((state) => state.setLoading);
const [apiKey, setApiKey] = useState<string | null>( const [apiKey, setApiKey] = useState<string | null>(
cookies.get("apikey_tkn_lflw") cookies.get("apikey_tkn_lflw"),
); );
const getFoldersApi = useFolderStore((state) => state.getFoldersApi);
useEffect(() => { useEffect(() => {
const storedAccessToken = cookies.get("access_token_lf"); const storedAccessToken = cookies.get("access_token_lf");
@ -59,11 +61,11 @@ export function AuthProvider({ children }): React.ReactElement {
function getUser() { function getUser() {
getLoggedUser() getLoggedUser()
.then((user) => { .then(async (user) => {
setUserData(user); setUserData(user);
setLoading(false);
const isSuperUser = user!.is_superuser; const isSuperUser = user!.is_superuser;
setIsAdmin(isSuperUser); setIsAdmin(isSuperUser);
await getFoldersApi(true);
}) })
.catch((error) => { .catch((error) => {
setLoading(false); setLoading(false);

View file

@ -20,8 +20,7 @@ export default function LoginPage(): JSX.Element {
useState<loginInputStateType>(CONTROL_LOGIN_STATE); useState<loginInputStateType>(CONTROL_LOGIN_STATE);
const { password, username } = inputState; const { password, username } = inputState;
const { login, isAuthenticated, setUserData, setIsAdmin } = const { login } = useContext(AuthContext);
useContext(AuthContext);
const navigate = useNavigate(); const navigate = useNavigate();
const setErrorData = useAlertStore((state) => state.setErrorData); const setErrorData = useAlertStore((state) => state.setErrorData);

View file

@ -47,7 +47,6 @@ const ProfilePictureFormComponent = ({
} }
return prev; return prev;
}); });
setLoading(false);
}); });
} }
}) })