Skip to content

Commit d9e2bdd

Browse files
committed
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.
1 parent 6578ac0 commit d9e2bdd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

resources/js/components/page-editor.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class PageEditor {
4040
frequency: 30000,
4141
last: 0,
4242
};
43-
this.draftHasError = false;
4443

4544
if (this.pageId !== 0 && this.draftsEnabled) {
4645
window.setTimeout(() => {
@@ -115,17 +114,19 @@ class PageEditor {
115114

116115
try {
117116
const resp = await window.$http.put(`/ajax/page/${this.pageId}/save-draft`, data);
118-
this.draftHasError = false;
119117
if (!this.isNewDraft) {
120118
this.toggleDiscardDraftVisibility(true);
121119
}
122120
this.draftNotifyChange(`${resp.data.message} ${Dates.utcTimeStampToLocalTime(resp.data.timestamp)}`);
123121
this.autoSave.last = Date.now();
124122
} catch (err) {
125-
if (!this.draftHasError) {
126-
this.draftHasError = true;
127-
window.$events.emit('error', this.autosaveFailText);
128-
}
123+
// Save the editor content in LocalStorage as a last resort, just in case.
124+
try {
125+
const saveKey = `draft-save-fail-${(new Date()).toISOString()}`;
126+
window.localStorage.setItem(saveKey, JSON.stringify(data));
127+
} catch (err) {}
128+
129+
window.$events.emit('error', this.autosaveFailText);
129130
}
130131

131132
}

0 commit comments

Comments
 (0)