diff --git a/ghost/admin/app/controllers/lexical-editor.js b/ghost/admin/app/controllers/lexical-editor.js index c77deca882..93942639e3 100644 --- a/ghost/admin/app/controllers/lexical-editor.js +++ b/ghost/admin/app/controllers/lexical-editor.js @@ -194,10 +194,17 @@ export default class LexicalEditorController extends Controller { // eslint-disable-next-line ghost/ember/no-observers @observes('post.currentState.stateName') _pushPostState() { - const stateName = this.post?.currentState.stateName; + const post = this.post; + + if (!post) { + return; + } + + const {stateName, isDeleted, isDirty, isEmpty, isLoading, isLoaded, isNew, isSaving, isValid} = post.currentState; if (stateName) { - console.log('post state changed:', stateName); // eslint-disable-line no-console - this._postStates.push(stateName); + const postState = [stateName, {isDeleted, isDirty, isEmpty, isLoading, isLoaded, isNew, isSaving, isValid}]; + console.log('post state changed:', ...postState); // eslint-disable-line no-console + this._postStates.push(postState); } } @@ -318,7 +325,7 @@ export default class LexicalEditorController extends Controller { } catch (err) { // ignore errors } - + // save 3 seconds after last edit this._autosaveTask.perform(); // force save at 60 seconds diff --git a/ghost/admin/tests/unit/controllers/editor-test.js b/ghost/admin/tests/unit/controllers/editor-test.js index eba84918e3..d1557c5086 100644 --- a/ghost/admin/tests/unit/controllers/editor-test.js +++ b/ghost/admin/tests/unit/controllers/editor-test.js @@ -477,11 +477,15 @@ describe('Unit: Controller: lexical-editor', function () { it('_getNotFoundErrorContext() includes all post states', async function () { const newPost = store.createRecord('post'); controller.setPost(newPost); - controller.post = {currentState: {stateName: 'state.one'}}; - controller.post = {currentState: {stateName: 'state.two'}}; - expect(controller._getNotFoundErrorContext().allPostStates).to.deep.equal( - ['root.loaded.created.uncommitted', 'state.one', 'state.two'] - ); + controller.post = {currentState: {stateName: 'state.one', isDirty: true}}; + controller.post = {currentState: {stateName: 'state.two', isDirty: false}}; + const allPostStates = controller._getNotFoundErrorContext().allPostStates; + const expectedStates = [ + ['root.loaded.created.uncommitted', {isDeleted: false, isDirty: true, isEmpty: false, isLoading: false, isLoaded: true, isNew: true, isSaving: false, isValid: true}], + ['state.one', {isDeleted: undefined, isDirty: true, isEmpty: undefined, isLoading: undefined, isLoaded: undefined, isNew: undefined, isSaving: undefined, isValid: undefined}], + ['state.two', {isDeleted: undefined, isDirty: false, isEmpty: undefined, isLoading: undefined, isLoaded: undefined, isNew: undefined, isSaving: undefined, isValid: undefined}] + ]; + expect(allPostStates).to.deep.equal(expectedStates); }); }); });