From 2619ec181b13fa3fd6c843fe1440b1f033cca404 Mon Sep 17 00:00:00 2001 From: Matin Dehghanian Date: Fri, 6 Dec 2024 13:03:29 +0330 Subject: [PATCH] Refactor isOffSections logic to handle environment variable parsing more robustly --- src/App.jsx | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 9497134..9abc031 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -75,10 +75,13 @@ function App() { ? `${data.username} Sub Info` : `${import.meta.env.VITE_BRAND_NAME || "Ourenus"} Sub Info`; - const isOffSections = useMemo(() => { - try { - return JSON.parse( - import.meta.env.VITE_OFF_SECTIONS || { + const isOffSections = useMemo(() => { + try { + const envValue = import.meta.env.VITE_OFF_SECTIONS; + if (envValue) { + return JSON.parse(envValue); + } + return { appsBox: true, logoBox: true, timeBox: true, @@ -86,13 +89,20 @@ function App() { userBox: true, supportBox: true, configs: true, - } - ); - } catch (error) { - console.error("Failed to parse VITE_OFF_SECTIONS:", error); - return {}; - } - }, []); + }; + } catch (error) { + console.error("Failed to parse VITE_OFF_SECTIONS:", error); + return { + appsBox: true, + logoBox: true, + timeBox: true, + usageBox: true, + userBox: true, + supportBox: true, + configs: true, + }; + } + }, []); return (