mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
🐛 Fixed incorrect autosave of published posts when leaving editor (#879)
closes https://github.com/TryGhost/Ghost/issues/9072 - the checks when leaving the editor were detecting that the autosave tasks were running and so forcing an immediate autosave even though the autosave tasks wouldn't do anything - exit early from autosave tasks if autosave isn't allowed
This commit is contained in:
parent
9f226416b2
commit
0a8d25fae2
2 changed files with 13 additions and 13 deletions
|
@ -71,28 +71,30 @@ export default Mixin.create({
|
||||||
|
|
||||||
// save 3 seconds after the last edit
|
// save 3 seconds after the last edit
|
||||||
_autosave: task(function* () {
|
_autosave: task(function* () {
|
||||||
|
if (!this.get('_canAutosave')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// force an instant save on first body edit for new posts
|
// force an instant save on first body edit for new posts
|
||||||
if (this.get('_canAutosave') && this.get('model.isNew')) {
|
if (this.get('model.isNew')) {
|
||||||
return this.get('autosave').perform();
|
return this.get('autosave').perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
yield timeout(AUTOSAVE_TIMEOUT);
|
yield timeout(AUTOSAVE_TIMEOUT);
|
||||||
|
|
||||||
if (this.get('_canAutosave')) {
|
|
||||||
this.get('autosave').perform();
|
this.get('autosave').perform();
|
||||||
}
|
|
||||||
}).restartable(),
|
}).restartable(),
|
||||||
|
|
||||||
// save at 60 seconds even if the user doesn't stop typing
|
// save at 60 seconds even if the user doesn't stop typing
|
||||||
_timedSave: task(function* () {
|
_timedSave: task(function* () {
|
||||||
|
if (!this.get('_canAutosave')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (!testing && true) {
|
while (!testing && true) {
|
||||||
yield timeout(TIMEDSAVE_TIMEOUT);
|
yield timeout(TIMEDSAVE_TIMEOUT);
|
||||||
|
|
||||||
if (this.get('_canAutosave')) {
|
|
||||||
this.get('autosave').perform();
|
this.get('autosave').perform();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}).drop(),
|
}).drop(),
|
||||||
|
|
||||||
// separate task for autosave so that it doesn't override a manual save
|
// separate task for autosave so that it doesn't override a manual save
|
||||||
|
|
|
@ -39,20 +39,18 @@ export default Mixin.create(styleBody, ShortcutsRoute, {
|
||||||
let controllerIsDirty = controller.get('hasDirtyAttributes');
|
let controllerIsDirty = controller.get('hasDirtyAttributes');
|
||||||
let model = controller.get('model');
|
let model = controller.get('model');
|
||||||
let state = model.getProperties('isDeleted', 'isSaving', 'hasDirtyAttributes', 'isNew');
|
let state = model.getProperties('isDeleted', 'isSaving', 'hasDirtyAttributes', 'isNew');
|
||||||
let deletedWithoutChanges,
|
|
||||||
fromNewToEdit;
|
|
||||||
|
|
||||||
if (this.get('upgradeStatus.isRequired')) {
|
if (this.get('upgradeStatus.isRequired')) {
|
||||||
return this._super(...arguments);
|
return this._super(...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
fromNewToEdit = this.get('routeName') === 'editor.new'
|
let fromNewToEdit = this.get('routeName') === 'editor.new'
|
||||||
&& transition.targetName === 'editor.edit'
|
&& transition.targetName === 'editor.edit'
|
||||||
&& transition.intent.contexts
|
&& transition.intent.contexts
|
||||||
&& transition.intent.contexts[0]
|
&& transition.intent.contexts[0]
|
||||||
&& transition.intent.contexts[0].id === model.get('id');
|
&& transition.intent.contexts[0].id === model.get('id');
|
||||||
|
|
||||||
deletedWithoutChanges = state.isDeleted
|
let deletedWithoutChanges = state.isDeleted
|
||||||
&& (state.isSaving || !state.hasDirtyAttributes);
|
&& (state.isSaving || !state.hasDirtyAttributes);
|
||||||
|
|
||||||
if (!fromNewToEdit && !deletedWithoutChanges && controllerIsDirty) {
|
if (!fromNewToEdit && !deletedWithoutChanges && controllerIsDirty) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue