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:
parent
6578ac0b4a
commit
d9e2bddee4
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user