@@ -171,6 +171,9 @@ class Source extends Component {
171
171
if ( this . codeMirror . getValue ( ) !== nextProps . source ) {
172
172
this . codeMirror . setValue ( nextProps . source ) ;
173
173
}
174
+ if ( nextProps . importError ) {
175
+ this . codeMirror . options . readOnly = true ;
176
+ }
174
177
}
175
178
176
179
onChanged ( doc , change ) {
@@ -234,6 +237,14 @@ class Editor extends Component {
234
237
this . generate ( ) ;
235
238
} else {
236
239
const json = await loadSketch ( this . props . id ) ;
240
+ if ( json === null ) {
241
+ const err = `Error: Could not import sketch named "${ this . props . id } ".` ;
242
+ this . setState ( { loading : false , debugOutput : err , source : err } ) ;
243
+ if ( this . props . onImportError ) {
244
+ this . props . onImportError ( ) ;
245
+ }
246
+ return ;
247
+ }
237
248
const sketch = Object . assign ( { key : this . props . id } , json ) ;
238
249
let newState = { loading : false , source : sketch . source } ;
239
250
localSource = window . localStorage . getItem ( this . props . id ) ;
@@ -365,7 +376,7 @@ class Editor extends Component {
365
376
h ( SeedPicker , { seed : this . state . seed , onSetSeed : this . onSetSeed . bind ( this ) , onPrevSeed : this . onPrevSeed . bind ( this ) , onNextSeed : this . onNextSeed . bind ( this ) } )
366
377
) ,
367
378
h ( 'div' , { className : 'editor__source' } ,
368
- h ( Source , { source, loading : this . state . loading , onSourceChanged : this . onSourceChanged . bind ( this ) } )
379
+ h ( Source , { source, loading : this . state . loading , importError : props . importError , onSourceChanged : this . onSourceChanged . bind ( this ) } )
369
380
) ,
370
381
debugView
371
382
) ,
@@ -392,6 +403,10 @@ class Sketch extends Component {
392
403
this . state = { saving : false , unsaved : false , source : undefined , seed : undefined } ;
393
404
}
394
405
406
+ onImportError ( ) {
407
+ this . setState ( { importError : true } ) ;
408
+ }
409
+
395
410
onSourceChanged ( source , initialLoad , localSource = false ) {
396
411
this . setState ( { unsaved : localSource || ! initialLoad , source } ) ;
397
412
if ( ! initialLoad ) {
@@ -442,10 +457,12 @@ class Sketch extends Component {
442
457
let saveLabel = state . saving ? 'Saving...' : 'Save' ;
443
458
return h ( 'div' , { class : 'app' } ,
444
459
h ( Header , { unsaved : ! ! state . unsaved } ,
445
- h ( 'button' , { class : 'button save-button' + ( state . unsaved ? ' unsaved' : '' ) , onClick : this . onSave . bind ( this ) , disabled : state . saving } , saveLabel )
460
+ h ( 'button' , { class : 'button save-button' + ( state . unsaved ? ' unsaved' : '' ) + ( state . importError ? ' disabled' : '' ) , onClick : this . onSave . bind ( this ) , disabled : state . saving } , saveLabel )
446
461
) ,
447
462
h ( Editor , {
448
463
id : props . id ,
464
+ importError : state . importError ,
465
+ onImportError : this . onImportError . bind ( this ) ,
449
466
onSourceChanged : this . onSourceChanged . bind ( this ) ,
450
467
onSeedChanged : this . onSeedChanged . bind ( this ) ,
451
468
headerRight : h ( 'a' , { href :'/docs' , target : '_blank' } , 'Documentation' )
0 commit comments