Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: functionality to add code from url and github gists #94

Merged
merged 9 commits into from
Aug 31, 2023
36 changes: 35 additions & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import LoadLFortran from "../components/LoadLFortran";
import preinstalled_programs from "../utils/preinstalled_programs";
import { useIsMobile } from "../components/useIsMobile";

import { useState } from "react";
import { useState, useEffect } from "react";
import { Col, Row, Spin } from "antd";
import { notification } from "antd";
import { LoadingOutlined } from "@ant-design/icons";
Expand Down Expand Up @@ -49,6 +49,40 @@ export default function Home() {

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

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

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

async function fetchData() {
const url = window.location.search;
const gist = "https://gist.githubusercontent.com/";
const urlParams = new URLSearchParams(url);

if (urlParams.get("code")) {
setSourceCode(decodeURIComponent(urlParams.get("code")));
} 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"
);

})
.catch((error) => {
console.error("Error fetching data:", error);
openNotification("error fetching .", "bottomRight");
});
}
}

async function handleUserTabChange(key) {
if (key == "STDOUT") {
if(sourceCode.trim() === ""){
Expand Down