mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-23 23:29:59 +08: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:
@ -40,7 +40,6 @@ class PageEditor {
|
|||||||
frequency: 30000,
|
frequency: 30000,
|
||||||
last: 0,
|
last: 0,
|
||||||
};
|
};
|
||||||
this.draftHasError = false;
|
|
||||||
|
|
||||||
if (this.pageId !== 0 && this.draftsEnabled) {
|
if (this.pageId !== 0 && this.draftsEnabled) {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
@ -115,17 +114,19 @@ class PageEditor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await window.$http.put(`/ajax/page/${this.pageId}/save-draft`, data);
|
const resp = await window.$http.put(`/ajax/page/${this.pageId}/save-draft`, data);
|
||||||
this.draftHasError = false;
|
|
||||||
if (!this.isNewDraft) {
|
if (!this.isNewDraft) {
|
||||||
this.toggleDiscardDraftVisibility(true);
|
this.toggleDiscardDraftVisibility(true);
|
||||||
}
|
}
|
||||||
this.draftNotifyChange(`${resp.data.message} ${Dates.utcTimeStampToLocalTime(resp.data.timestamp)}`);
|
this.draftNotifyChange(`${resp.data.message} ${Dates.utcTimeStampToLocalTime(resp.data.timestamp)}`);
|
||||||
this.autoSave.last = Date.now();
|
this.autoSave.last = Date.now();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!this.draftHasError) {
|
// Save the editor content in LocalStorage as a last resort, just in case.
|
||||||
this.draftHasError = true;
|
try {
|
||||||
window.$events.emit('error', this.autosaveFailText);
|
const saveKey = `draft-save-fail-${(new Date()).toISOString()}`;
|
||||||
}
|
window.localStorage.setItem(saveKey, JSON.stringify(data));
|
||||||
|
} catch (err) {}
|
||||||
|
|
||||||
|
window.$events.emit('error', this.autosaveFailText);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user