Skip to content

Commit

Permalink
Fix flicker and auto-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Sep 1, 2023
1 parent 523176a commit f258435
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 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
11 changes: 8 additions & 3 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand All @@ -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;
Expand All @@ -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"
Expand All @@ -81,6 +86,7 @@ export default function Home() {
});
} else {
setSourceCode(preinstalled_programs.basic.mandelbrot);
setDataFetch(true);
}
}

Expand Down Expand Up @@ -152,7 +158,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 f258435

Please sign in to comment.