Skip to content

Commit

Permalink
add: functionality to add code from url and github gists (#94)
Browse files Browse the repository at this point in the history
* add: functionality to support github gists

* add: functionality to support url codes

* add: functionality to support url codes

* add: functionality to support url codes

* add: functionality to support url codes

* add: functionality to support gist and url

* Update pages/index.js

Co-authored-by: Shaikh Ubaid <[email protected]>

* Update pages/index.js

Co-authored-by: Shaikh Ubaid <[email protected]>

* Specify moduleReady as dep for handleUserTabChange()

Fix minor indentations

---------

Co-authored-by: Shaikh Ubaid <[email protected]>
  • Loading branch information
henilp105 and Shaikh-Ubaid authored Aug 31, 2023
1 parent 4fc083b commit 65cea79
Showing 1 changed file with 35 additions and 1 deletion.
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

0 comments on commit 65cea79

Please sign in to comment.