mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 04:05:57 +00: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,
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user