@@ -137,20 +137,32 @@ export const downLoad_notebook = (state) => {
137
137
* @param {Array } array of package CDNs to load
138
138
* @param {* } callback
139
139
*/
140
- export const load_package = ( array , callback ) => {
140
+ // eslint-disable-next-line consistent-return
141
+ const load_package = async ( array , callback ) => {
141
142
try {
142
- // document.getElementById("cell-running").style.display = "block";
143
+ document . getElementById ( "play" ) . style . display = "none" ;
144
+ document . getElementById ( "activity-loader" ) . style . display = "block" ;
143
145
const loader = function ( src , handler ) {
144
146
const script = document . createElement ( "script" ) ;
145
- console . log ( src ) ;
146
147
script . type = "text/javascript" ;
147
148
script . src = src ;
148
- const a = "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest" ;
149
- console . log ( a ) ;
150
149
script . onload = script . onreadystatechange = function ( ) {
151
150
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" ;
152
156
handler ( ) ;
153
157
} ;
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
+ } ;
154
166
script . async = true ;
155
167
document . body . appendChild ( script ) ;
156
168
eval ( script ) ;
@@ -162,8 +174,8 @@ export const load_package = (array, callback) => {
162
174
// eslint-disable-next-line no-unused-expressions
163
175
callback && callback ( ) ;
164
176
}
165
- // document.getElementById("cell-running").style.display = "none";
166
177
} ) ( ) ;
178
+ return "done" ;
167
179
} catch ( error ) {
168
180
console . log ( error ) ;
169
181
}
0 commit comments