From afff3228c796326e8bb9fd433ff271d6940e0d0f Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Mon, 8 Apr 2024 21:42:34 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(App.tsx):=20refactor=20code=20to?= =?UTF-8?q?=20use=20async/await=20syntax=20for=20fetching=20data=20when=20?= =?UTF-8?q?the=20user=20is=20authenticated=20=F0=9F=90=9B=20(App.tsx):=20h?= =?UTF-8?q?andle=20errors=20when=20fetching=20data=20and=20log=20them=20to?= =?UTF-8?q?=20the=20console=20for=20debugging=20purposes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/App.tsx | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index da3c50325..5e65ee890 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -56,18 +56,21 @@ export default function App() { refreshStars(); refreshVersion(); - // If the user is authenticated, fetch the types. This code is important to check if the user is auth because of the execution order of the useEffect hooks. - if (isAuthenticated === true) { - // get data from db - getTypes().then(() => { - refreshFlows(); - }); - getGlobalVariables().then((res) => { - setGlobalVariables(res); - }); - checkHasStore(); - fetchApiData(); - } + const fetchData = async () => { + if (isAuthenticated) { + try { + await getTypes(); + refreshFlows(); + const res = await getGlobalVariables(); + setGlobalVariables(res); + checkHasStore(); + fetchApiData(); + } catch (error) { + console.error("Failed to fetch data:", error); + } + } + }; + fetchData(); }, [isAuthenticated]); useEffect(() => {