diff --git a/components/LoadLFortran.js b/components/LoadLFortran.js index 96e8505..b82e2c7 100644 --- a/components/LoadLFortran.js +++ b/components/LoadLFortran.js @@ -162,7 +162,6 @@ function LoadLFortran({ lfortran_funcs, openNotification, myPrint, - handleUserTabChange }) { const { basePath } = useRouter(); @@ -179,7 +178,6 @@ function LoadLFortran({ setModuleReady(true); openNotification("LFortran Module Initialized!", "bottomRight"); console.log("LFortran Module Initialized!"); - handleUserTabChange("STDOUT"); }, [moduleReady]); // update the callback if the state changes return ( diff --git a/pages/index.js b/pages/index.js index ea291de..bd12ddc 100644 --- a/pages/index.js +++ b/pages/index.js @@ -45,6 +45,7 @@ export default function Home() { const [exampleName, setExampleName] = useState("main"); const [activeTab, setActiveTab] = useState("STDOUT"); const [output, setOutput] = useState(""); + const [dataFetch, setDataFetch] = useState(false); const isMobile = useIsMobile(); const myHeight = ((!isMobile) ? "calc(100vh - 170px)" : "calc(50vh - 85px)"); @@ -54,8 +55,10 @@ export default function Home() { }, []); useEffect(() => { - if(moduleReady) { handleUserTabChange("STDOUT"); } - }, [moduleReady]); + if(moduleReady && dataFetch) { + handleUserTabChange("STDOUT"); + } + }, [moduleReady, dataFetch]); async function fetchData() { const url = window.location.search; @@ -64,12 +67,14 @@ export default function Home() { if (urlParams.get("code")) { setSourceCode(decodeURIComponent(urlParams.get("code"))); + setDataFetch(true); } else if (urlParams.get("gist")) { const gistUrl = gist + urlParams.get("gist") + "/raw/"; fetch(gistUrl) .then((response) => response.text()) .then((data) => { setSourceCode(data); + setDataFetch(true); openNotification( "Source Code loaded from gist.", "bottomRight" @@ -81,6 +86,7 @@ export default function Home() { }); } else { setSourceCode(preinstalled_programs.basic.mandelbrot); + setDataFetch(true); } } @@ -152,7 +158,6 @@ export default function Home() { lfortran_funcs={lfortran_funcs} openNotification={openNotification} myPrint={setOutput} - handleUserTabChange={handleUserTabChange} >