Skip to content

A platform for community discussion. Free, open, simple.

FIX: resolve discard draft keep editing (#32667)

David Battersby804bdcfe5fba
diff --git a/app/assets/javascripts/discourse/app/components/modal/discard-draft.gjs b/app/assets/javascripts/discourse/app/components/modal/discard-draft.gjs
index 10acf7e6d95..ebe53d94f2c 100644
--- a/app/assets/javascripts/discourse/app/components/modal/discard-draft.gjs
+++ b/app/assets/javascripts/discourse/app/components/modal/discard-draft.gjs
@@ -17,6 +17,12 @@ export default class DiscardDraftModal extends Component {
this.args.closeModal();
}
+ @action
+ async keepEditing() {
+ await this.args.model.onKeepEditing();
+ this.args.closeModal();
+ }
+
<template>
<DModal
@closeModal={{@closeModal}}
@@ -45,7 +51,7 @@ export default class DiscardDraftModal extends Component {
{{/if}}
<DButton
@label="post.cancel_composer.keep_editing"
- @action={{@closeModal}}
+ @action={{this.keepEditing}}
class="keep-editing"
/>
</:footer>
diff --git a/app/assets/javascripts/discourse/app/services/composer.js b/app/assets/javascripts/discourse/app/services/composer.js
index f7096e9d7c2..67b614fac90 100644
--- a/app/assets/javascripts/discourse/app/services/composer.js
+++ b/app/assets/javascripts/discourse/app/services/composer.js
@@ -1442,8 +1442,10 @@ export default class ComposerService extends Service {
}
}
- await this.cancelComposer(opts);
- await this.open(opts);
+ const retry = await this.cancelComposer(opts);
+ if (retry) {
+ await this.open(opts);
+ }
return;
}
@@ -1627,7 +1629,7 @@ export default class ComposerService extends Service {
})
.finally(() => {
this.appEvents.trigger("composer:cancelled");
- resolve();
+ resolve(true);
});
},
onSaveDraft: () => {
@@ -1635,8 +1637,9 @@ export default class ComposerService extends Service {
this.model.clearState();
this.close();
this.appEvents.trigger("composer:cancelled");
- return resolve();
+ return resolve(true);
},
+ onKeepEditing: () => resolve(false),
},
});
} else {
diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
index 712246c11b8..3a86f2deb98 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
@@ -469,6 +469,51 @@ import { i18n } from "discourse-i18n";
.hasNoValue("discards draft and reset composer textarea");
});
+ test("Autosaves drafts after clicking keep editing in discard modal", async function (assert) {
+ pretender.post("/drafts.json", function () {
+ assert.step("saveDraft");
+ return response(200, {});
+ });
+
+ await visit("/t/internationalization-localization/280");
+
+ await click("#topic-footer-buttons .btn.create");
+
+ await fillIn(".d-editor-input", "this is draft content of the reply");
+
+ assert.verifySteps(["saveDraft"], "first draft is auto saved");
+
+ await click("#reply-control button.cancel");
+
+ assert
+ .dom(".discard-draft-modal.modal")
+ .exists("pops up the discard drafts modal");
+
+ await click(".d-modal__footer button.keep-editing");
+ assert.dom(".discard-draft-modal.modal").doesNotExist("hides modal");
+
+ assert
+ .dom(".d-editor-input")
+ .hasValue(
+ "this is draft content of the reply",
+ "composer has the content of the first draft"
+ );
+
+ await fillIn(
+ ".d-editor-input",
+ "this is the updated content of the reply",
+ "update content in the composer"
+ );
+
+ assert.verifySteps(["saveDraft"], "second draft is saved");
+
+ await click("#reply-control button.create");
+
+ assert
+ .dom(".topic-post:last-of-type .cooked p")
+ .hasText("this is the updated content of the reply");
+ });
+
test("Create an enqueued Reply", async function (assert) {
pretender.post("/posts", function () {
return response(200, {