From 7ecf0c672a1884ec4d6c5157248ae8036cac2c43 Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 5 Jan 2024 10:41:05 +0100 Subject: [PATCH] Use undo history to track 'isDirty' instead of comparing html strings --- .changeset/smooth-maps-type.md | 5 +++++ app/controllers/agendapoints/edit.js | 7 ++++++- app/controllers/regulatory-statements/edit.js | 7 ++++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/smooth-maps-type.md diff --git a/.changeset/smooth-maps-type.md b/.changeset/smooth-maps-type.md new file mode 100644 index 000000000..2c6149f73 --- /dev/null +++ b/.changeset/smooth-maps-type.md @@ -0,0 +1,5 @@ +--- +"frontend-gelinkt-notuleren": patch +--- + +Correctly track the saved state so we only ask to save changes when changes have been made diff --git a/app/controllers/agendapoints/edit.js b/app/controllers/agendapoints/edit.js index dcac1d906..a066d829d 100644 --- a/app/controllers/agendapoints/edit.js +++ b/app/controllers/agendapoints/edit.js @@ -94,6 +94,7 @@ import { GEMEENTE, OCMW, } from '../../utils/bestuurseenheid-classificatie-codes'; +import { undo } from '@lblod/ember-rdfa-editor/plugins/history'; export default class AgendapointsEditController extends Controller { @service store; @@ -258,7 +259,11 @@ export default class AgendapointsEditController extends Controller { } get dirty() { - return this.editorDocument.content !== this.controller?.htmlContent; + // Since we clear the undo history when saving, this works. If we want to maintain undo history + // on save, we would need to add functionality to the editor to track what is the 'saved' state + return this.controller?.checkCommand(undo, { + view: this.controller?.mainEditorView, + }); } get editorDocument() { diff --git a/app/controllers/regulatory-statements/edit.js b/app/controllers/regulatory-statements/edit.js index ff76e75c0..7fa36e10e 100644 --- a/app/controllers/regulatory-statements/edit.js +++ b/app/controllers/regulatory-statements/edit.js @@ -90,6 +90,7 @@ import { GEMEENTE, OCMW, } from '../../utils/bestuurseenheid-classificatie-codes'; +import { undo } from '@lblod/ember-rdfa-editor/plugins/history'; export default class RegulatoryStatementsRoute extends Controller { @service documentService; @@ -239,7 +240,11 @@ export default class RegulatoryStatementsRoute extends Controller { }); get dirty() { - return this.editorDocument.content !== this.controller?.htmlContent; + // Since we clear the undo history when saving, this works. If we want to maintain undo history + // on save, we would need to add functionality to the editor to track what is the 'saved' state + return this.controller?.checkCommand(undo, { + view: this.controller?.mainEditorView, + }); } get editorDocument() {