@@ -251,15 +251,18 @@ function App() {
251
251
const [ galleryLoaded , setGalleryLoaded ] = useState ( false ) ;
252
252
253
253
const [ consoleMessages , setConsoleMessages ] = useState < ConsoleMessage [ ] > ( [ ] ) ;
254
- function appendConsole ( type : ConsoleMessageType , message : string ) {
255
- setConsoleMessages ( ( prevConsoleMessages ) => [
256
- ...prevConsoleMessages ,
257
- { type, message, id : crypto . randomUUID ( ) } ,
258
- ] ) ;
259
- if ( ! consoleExpanded && type !== "log" ) {
260
- rightSideRef . current ?. toggleExpanded ( ) ;
261
- }
262
- }
254
+ const appendConsole = useCallback (
255
+ function appendConsole ( type : ConsoleMessageType , message : string ) {
256
+ setConsoleMessages ( ( prevConsoleMessages ) => [
257
+ ...prevConsoleMessages ,
258
+ { type, message, id : crypto . randomUUID ( ) } ,
259
+ ] ) ;
260
+ if ( ! consoleExpanded && type !== "log" ) {
261
+ rightSideRef . current ?. toggleExpanded ( ) ;
262
+ }
263
+ } ,
264
+ [ consoleExpanded ] ,
265
+ ) ;
263
266
264
267
function resetConsole ( ) {
265
268
// the console should only be cleared by the Bucket when the viewer page
@@ -373,6 +376,26 @@ function App() {
373
376
html : data . html ,
374
377
} ) ;
375
378
setReadyForViewer ( true ) ;
379
+ } else if ( searchParams . has ( "gist" ) ) {
380
+ // This is currently for legacy support only so old links on GH or the forums don't break
381
+ fetch ( `https://api.github.com/gists/${ searchParams . get ( "gist" ) } ` )
382
+ . then ( ( data ) => data . json ( ) )
383
+ . then ( function ( data ) {
384
+ const files = data . files ;
385
+ const code = files [ "Cesium-Sandcastle.js" ] . content ;
386
+ const html =
387
+ files [ "Cesium-Sandcastle.html" ] ?. content ?? defaultHtmlCode ;
388
+ dispatch ( { type : "setAndRun" , code : code , html : html } ) ;
389
+ setTitle ( "Gist Import" ) ;
390
+ setReadyForViewer ( true ) ;
391
+ } )
392
+ . catch ( function ( error ) {
393
+ appendConsole (
394
+ "error" ,
395
+ `Unable to GET gist from GitHub API. This could be due to too many requests from your IP or an incorrect id. Try again in an hour or copy and paste the code from the gist: https://gist.github.com/${ searchParams . get ( "gist" ) } ` ,
396
+ ) ;
397
+ console . log ( error ) ;
398
+ } ) ;
376
399
} else if ( searchParams . has ( "src" ) ) {
377
400
const legacyId = searchParams . get ( "src" ) ;
378
401
if ( ! legacyId ) {
@@ -400,7 +423,7 @@ function App() {
400
423
}
401
424
}
402
425
} ,
403
- [ galleryLoaded , legacyIdMap , loadGalleryItem ] ,
426
+ [ galleryLoaded , legacyIdMap , loadGalleryItem , appendConsole ] ,
404
427
) ;
405
428
406
429
useEffect ( ( ) => loadFromUrl ( ) , [ galleryLoaded , galleryItems , loadFromUrl ] ) ;
0 commit comments