Skip to content

Commit

Permalink
Use undo history to track 'isDirty' instead of comparing html strings
Browse files Browse the repository at this point in the history
  • Loading branch information
piemonkey committed Jan 5, 2024
1 parent 7e2b31f commit 7ecf0c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-maps-type.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion app/controllers/agendapoints/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/regulatory-statements/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 7ecf0c6

Please sign in to comment.