1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-10-30 07:32:39 +01:00

Added some robustness to page draft saving

- Updated so that a warning is always shown on error, Not just on first
in chain.
- Added last-resort localStorage content saving.
This commit is contained in:
Dan Brown 2020-09-13 19:32:45 +01:00
parent 6578ac0b4a
commit d9e2bddee4
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View File

@ -40,7 +40,6 @@ class PageEditor {
frequency: 30000,
last: 0,
};
this.draftHasError = false;
if (this.pageId !== 0 && this.draftsEnabled) {
window.setTimeout(() => {
@ -115,17 +114,19 @@ class PageEditor {
try {
const resp = await window.$http.put(`/ajax/page/${this.pageId}/save-draft`, data);
this.draftHasError = false;
if (!this.isNewDraft) {
this.toggleDiscardDraftVisibility(true);
}
this.draftNotifyChange(`${resp.data.message} ${Dates.utcTimeStampToLocalTime(resp.data.timestamp)}`);
this.autoSave.last = Date.now();
} catch (err) {
if (!this.draftHasError) {
this.draftHasError = true;
window.$events.emit('error', this.autosaveFailText);
}
// Save the editor content in LocalStorage as a last resort, just in case.
try {
const saveKey = `draft-save-fail-${(new Date()).toISOString()}`;
window.localStorage.setItem(saveKey, JSON.stringify(data));
} catch (err) {}
window.$events.emit('error', this.autosaveFailText);
}
}