Skip to content

Commit cd33efe

Browse files
committed
feat: ✨ Added spinner to cell loading package and response message to cell
1 parent 7e0b3ce commit cd33efe

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/Cell.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import CodeMirror from "react-codemirror";
1212
import { Remarkable } from "remarkable";
1313
import { CgMathPlus, CgArrowUp, CgArrowDown, CgTrash } from "react-icons/cg";
1414
import { BsFillCaretRightFill } from "react-icons/bs";
15-
// eslint-disable-next-line no-unused-vars
1615
import {
1716
AddCellButton,
1817
CellButton,
@@ -23,6 +22,7 @@ import {
2322
RunContainer,
2423
CellBodyContainer,
2524
} from "./Cell.style";
25+
import roll from "./static/rolling.svg";
2626

2727
require("codemirror/lib/codemirror.css");
2828
require("codemirror/mode/javascript/javascript");
@@ -45,7 +45,7 @@ export default function Cell({
4545
setShowMoreCellButton("none");
4646
}
4747
}, [cellId, currentCell]);
48-
const getCode = () => {
48+
const getCode = async () => {
4949
if (cell.type === "code") {
5050
const input = refCode.current.getCodeMirror().getValue();
5151
try {
@@ -164,6 +164,7 @@ export default function Cell({
164164
<RunContainer>
165165
{currentCell === cellId ? (
166166
<div
167+
id="play"
167168
onClick={() => {
168169
getCode();
169170
}}
@@ -173,6 +174,13 @@ export default function Cell({
173174
) : (
174175
<div>[{cellId}]:</div>
175176
)}
177+
<img
178+
id="activity-loader"
179+
style={{ display: "none" }}
180+
width="30px"
181+
src={roll}
182+
alt="running-cell"
183+
/>
176184
</RunContainer>
177185
<CellBodyContainer>
178186
<CellHead>
@@ -284,6 +292,7 @@ export default function Cell({
284292
onClick={() => {
285293
disableOutput();
286294
}}
295+
id="cell-output"
287296
></Output>
288297
</div>
289298
</>

src/static/rolling.svg

Lines changed: 6 additions & 0 deletions
Loading

src/utils.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,32 @@ export const downLoad_notebook = (state) => {
137137
* @param {Array} array of package CDNs to load
138138
* @param {*} callback
139139
*/
140-
export const load_package = (array, callback) => {
140+
// eslint-disable-next-line consistent-return
141+
const load_package = async (array, callback) => {
141142
try {
142-
// document.getElementById("cell-running").style.display = "block";
143+
document.getElementById("play").style.display = "none";
144+
document.getElementById("activity-loader").style.display = "block";
143145
const loader = function (src, handler) {
144146
const script = document.createElement("script");
145-
console.log(src);
146147
script.type = "text/javascript";
147148
script.src = src;
148-
const a = "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest";
149-
console.log(a);
150149
script.onload = script.onreadystatechange = function () {
151150
script.onreadystatechange = script.onload = null;
151+
document.getElementById("play").style.display = "block";
152+
document.getElementById("activity-loader").style.display = "none";
153+
document.getElementById("cell-output").innerHTML =
154+
"Package sucessfully loaded";
155+
document.getElementById("cell-output").style.color = "white";
152156
handler();
153157
};
158+
script.onerror = function (error) {
159+
document.getElementById("play").style.display = "block";
160+
document.getElementById("activity-loader").style.display = "none";
161+
document.getElementById(
162+
"cell-output"
163+
).innerHTML = `Failed to load package ${error.path[0].src}. Check internet connection or package url`;
164+
document.getElementById("cell-output").style.color = "red";
165+
};
154166
script.async = true;
155167
document.body.appendChild(script);
156168
eval(script);
@@ -162,8 +174,8 @@ export const load_package = (array, callback) => {
162174
// eslint-disable-next-line no-unused-expressions
163175
callback && callback();
164176
}
165-
// document.getElementById("cell-running").style.display = "none";
166177
})();
178+
return "done";
167179
} catch (error) {
168180
console.log(error);
169181
}

0 commit comments

Comments
 (0)