Skip to content

Commit 5c7caf1

Browse files
committed
Warning and disabling saving and typing upon import error.
1 parent ef61f15 commit 5c7caf1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

css/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ a.underline {
130130
opacity: 1.0;
131131
}
132132

133+
.header__nav .save-button.disabled {
134+
display: none;
135+
}
136+
133137
/* Page */
134138

135139
.page {

js/editor.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ class Source extends Component {
171171
if (this.codeMirror.getValue() !== nextProps.source) {
172172
this.codeMirror.setValue(nextProps.source);
173173
}
174+
if (nextProps.importError) {
175+
this.codeMirror.options.readOnly = true;
176+
}
174177
}
175178

176179
onChanged(doc, change) {
@@ -234,6 +237,14 @@ class Editor extends Component {
234237
this.generate();
235238
} else {
236239
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+
}
237248
const sketch = Object.assign({ key: this.props.id }, json);
238249
let newState = { loading: false, source: sketch.source };
239250
localSource = window.localStorage.getItem(this.props.id);
@@ -365,7 +376,7 @@ class Editor extends Component {
365376
h(SeedPicker, { seed: this.state.seed, onSetSeed: this.onSetSeed.bind(this), onPrevSeed: this.onPrevSeed.bind(this), onNextSeed: this.onNextSeed.bind(this) })
366377
),
367378
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) })
369380
),
370381
debugView
371382
),
@@ -392,6 +403,10 @@ class Sketch extends Component {
392403
this.state = { saving: false, unsaved: false, source: undefined, seed: undefined };
393404
}
394405

406+
onImportError() {
407+
this.setState({ importError: true });
408+
}
409+
395410
onSourceChanged(source, initialLoad, localSource=false) {
396411
this.setState({ unsaved: localSource || !initialLoad, source });
397412
if (!initialLoad) {
@@ -442,10 +457,12 @@ class Sketch extends Component {
442457
let saveLabel = state.saving ? 'Saving...' : 'Save';
443458
return h('div', {class: 'app'},
444459
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)
446461
),
447462
h(Editor, {
448463
id: props.id,
464+
importError: state.importError,
465+
onImportError: this.onImportError.bind(this),
449466
onSourceChanged: this.onSourceChanged.bind(this),
450467
onSeedChanged: this.onSeedChanged.bind(this),
451468
headerRight: h('a', { href:'/docs', target: '_blank' }, 'Documentation')

0 commit comments

Comments
 (0)