From b81ea3b32eba46d90f68e85f236b547ad0aaa705 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sat, 2 Sep 2023 01:14:58 +0530 Subject: [PATCH 1/3] Fix indentation --- pages/index.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pages/index.js b/pages/index.js index d8fe6fd..4772064 100644 --- a/pages/index.js +++ b/pages/index.js @@ -50,11 +50,11 @@ export default function Home() { const myHeight = ((!isMobile) ? "calc(100vh - 170px)" : "calc(50vh - 85px)"); useEffect(() => { - fetchData(); - }, []); + fetchData(); + }, []); - useEffect(() => { - if(moduleReady){handleUserTabChange("STDOUT"); } + useEffect(() => { + if(moduleReady) { handleUserTabChange("STDOUT"); } }, [moduleReady]); async function fetchData() { @@ -69,12 +69,11 @@ export default function Home() { fetch(gistUrl) .then((response) => response.text()) .then((data) => { - setSourceCode(data); - openNotification( - "Source Code loaded from gist.", - "bottomRight" - ); - + setSourceCode(data); + openNotification( + "Source Code loaded from gist.", + "bottomRight" + ); }) .catch((error) => { console.error("Error fetching data:", error); From 523176a0688ab2d1c0f4029c76c794e7b36d9c74 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sat, 2 Sep 2023 01:16:50 +0530 Subject: [PATCH 2/3] No source code by default Also set default file name to main.f90 --- pages/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pages/index.js b/pages/index.js index 4772064..ea291de 100644 --- a/pages/index.js +++ b/pages/index.js @@ -41,8 +41,8 @@ var lfortran_funcs = { export default function Home() { const [moduleReady, setModuleReady] = useState(false); - const [sourceCode, setSourceCode] = useState(preinstalled_programs.basic.mandelbrot); - const [exampleName, setExampleName] = useState("mandelbrot"); + const [sourceCode, setSourceCode] = useState(""); + const [exampleName, setExampleName] = useState("main"); const [activeTab, setActiveTab] = useState("STDOUT"); const [output, setOutput] = useState(""); const isMobile = useIsMobile(); @@ -79,6 +79,8 @@ export default function Home() { console.error("Error fetching data:", error); openNotification("error fetching .", "bottomRight"); }); + } else { + setSourceCode(preinstalled_programs.basic.mandelbrot); } } From f258435e9a3a1cfd4672be69e94572729b081687 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sat, 2 Sep 2023 01:18:51 +0530 Subject: [PATCH 3/3] Fix flicker and auto-compile --- components/LoadLFortran.js | 2 -- pages/index.js | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) 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} >