Skip to content

Commit

Permalink
Merge pull request #105 from lfortran/fix_flicker_and_auto_run
Browse files Browse the repository at this point in the history
Fix flicker and auto run
  • Loading branch information
certik authored Sep 1, 2023
2 parents d2144c8 + f258435 commit 1e8bdb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 0 additions & 2 deletions components/LoadLFortran.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ function LoadLFortran({
lfortran_funcs,
openNotification,
myPrint,
handleUserTabChange
}) {

const { basePath } = useRouter();
Expand All @@ -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 (
Expand Down
34 changes: 20 additions & 14 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,24 @@ 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 [dataFetch, setDataFetch] = useState(false);
const isMobile = useIsMobile();

const myHeight = ((!isMobile) ? "calc(100vh - 170px)" : "calc(50vh - 85px)");

useEffect(() => {
fetchData();
}, []);
fetchData();
}, []);

useEffect(() => {
if(moduleReady){handleUserTabChange("STDOUT"); }
}, [moduleReady]);
useEffect(() => {
if(moduleReady && dataFetch) {
handleUserTabChange("STDOUT");
}
}, [moduleReady, dataFetch]);

async function fetchData() {
const url = window.location.search;
Expand All @@ -64,22 +67,26 @@ 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);
openNotification(
"Source Code loaded from gist.",
"bottomRight"
);

setSourceCode(data);
setDataFetch(true);
openNotification(
"Source Code loaded from gist.",
"bottomRight"
);
})
.catch((error) => {
console.error("Error fetching data:", error);
openNotification("error fetching .", "bottomRight");
});
} else {
setSourceCode(preinstalled_programs.basic.mandelbrot);
setDataFetch(true);
}
}

Expand Down Expand Up @@ -147,7 +154,6 @@ export default function Home() {
lfortran_funcs={lfortran_funcs}
openNotification={openNotification}
myPrint={setOutput}
handleUserTabChange={handleUserTabChange}
></LoadLFortran>

<Row gutter={[16, 16]}>
Expand Down

0 comments on commit 1e8bdb3

Please sign in to comment.