Skip to content

Commit

Permalink
fix: correctly reset editor to default content
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlatz committed Oct 1, 2024
1 parent 4caf7d9 commit 8bf5b5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion LocalBackup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export default class LocalBackup {
try {
return JSON.parse(schemaAsString);
} catch {
window.localStorage.removeItem(this.localStorageKey);
this.delete();
return null;
}
}

static delete() {
window.localStorage.removeItem(this.localStorageKey);
}
}
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ <h2>JSON à copier/coller</h2>
const resetButton = document.querySelector('#reset-button');
resetButton.addEventListener('click', () => {
if (window.confirm('Voulez-vous vraiment réinitialiser le module ? Toutes les modifications seront perdues.')) {
editor.setValue({})
LocalBackup.delete();
window.location.reload();
}
});

Expand Down Expand Up @@ -138,7 +139,9 @@ <h2>JSON à copier/coller</h2>

editor.on('ready', () => {
const schema = LocalBackup.load();
editor.setValue(schema);
if (schema) {
editor.setValue(schema);
}
});
</script>
</body>
Expand Down

0 comments on commit 8bf5b5d

Please sign in to comment.