Skip to content

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

FEATURE: Better composer controls for "Save & close (X)" and "Discard" (#33510)

Martin Brennan369cc65865dc
diff --git a/app/assets/javascripts/discourse/app/components/composer-container.gjs b/app/assets/javascripts/discourse/app/components/composer-container.gjs
index 118b8db9834..e201d90bb7a 100644
--- a/app/assets/javascripts/discourse/app/components/composer-container.gjs
+++ b/app/assets/javascripts/discourse/app/components/composer-container.gjs
@@ -200,6 +200,7 @@ export default class ComposerContainer extends Component {
@toggleToolbar={{this.composer.toggleToolbar}}
@toggleFullscreen={{this.composer.fullscreenComposer}}
@disableTextarea={{this.composer.disableTextarea}}
+ @saveAndClose={{this.composer.saveAndClose}}
/>
</div>
@@ -345,22 +346,11 @@ export default class ComposerContainer extends Component {
{{#if this.site.mobileView}}
<DButton
@action={{this.composer.cancel}}
- class="cancel btn-transparent"
- @icon={{if this.composer.canEdit "xmark" "trash-can"}}
+ @icon="trash-can"
+ class="discard-button btn-transparent"
@preventFocus={{true}}
- @title="close"
+ @title="composer.discard"
/>
- {{else}}
- <DButton
- @action={{this.composer.cancel}}
- class="cancel btn-transparent"
- @preventFocus={{true}}
- @title="close"
- @label="close"
- />
- {{/if}}
-
- {{#if this.site.mobileView}}
{{#if this.composer.model.noBump}}
<span class="no-bump">{{icon "anchor"}}</span>
@@ -467,6 +457,18 @@ export default class ComposerContainer extends Component {
</div>
{{/if}}
+ <div class="discard">
+ {{#unless this.site.mobileView}}
+ <DButton
+ @action={{this.composer.cancel}}
+ class="discard-button btn-transparent"
+ @preventFocus={{true}}
+ @title="composer.discard"
+ @label="composer.discard"
+ />
+ {{/unless}}
+ </div>
+
{{#if (and this.composer.allowPreview this.site.desktopView)}}
<DButton
@action={{this.composer.togglePreview}}
@@ -509,6 +511,7 @@ export default class ComposerContainer extends Component {
@toggleFullscreen={{this.composer.openIfDraft}}
@toggleComposer={{this.composer.toggle}}
@toggleToolbar={{this.composer.toggleToolbar}}
+ @saveAndClose={{this.composer.saveAndClose}}
/>
{{/if}}
{{/if}}
diff --git a/app/assets/javascripts/discourse/app/components/composer-toggles.gjs b/app/assets/javascripts/discourse/app/components/composer-toggles.gjs
index 120ccd547e1..aae3201f093 100644
--- a/app/assets/javascripts/discourse/app/components/composer-toggles.gjs
+++ b/app/assets/javascripts/discourse/app/components/composer-toggles.gjs
@@ -1,55 +1,44 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
-import { tagName } from "@ember-decorators/component";
+import Component from "@glimmer/component";
+import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import PluginOutlet from "discourse/components/plugin-outlet";
-import discourseComputed from "discourse/lib/decorators";
-@tagName("")
export default class ComposerToggles extends Component {
- @discourseComputed("composeState")
- toggleTitle(composeState) {
- return composeState === "draft" || composeState === "saving"
- ? "composer.abandon"
- : "composer.collapse";
+ @service site;
+
+ get showCollapseButton() {
+ return (
+ this.args.composeState !== "draft" && this.args.composeState !== "saving"
+ );
}
- @discourseComputed("showToolbar")
- toggleToolbarTitle(showToolbar) {
- return showToolbar ? "composer.hide_toolbar" : "composer.show_toolbar";
+ get toggleToolbarTitle() {
+ return this.args.showToolbar
+ ? "composer.hide_toolbar"
+ : "composer.show_toolbar";
}
- @discourseComputed("composeState")
- fullscreenTitle(composeState) {
- return composeState === "draft"
+ get fullscreenTitle() {
+ return this.args.composeState === "draft"
? "composer.open"
- : composeState === "fullscreen"
+ : this.args.composeState === "fullscreen"
? "composer.exit_fullscreen"
: "composer.enter_fullscreen";
}
- @discourseComputed("composeState")
- toggleIcon(composeState) {
- return composeState === "draft" || composeState === "saving"
- ? "xmark"
- : "angles-down";
- }
-
- @discourseComputed("composeState")
- fullscreenIcon(composeState) {
- return composeState === "draft"
+ get fullscreenIcon() {
+ return this.args.composeState === "draft"
? "angles-up"
- : composeState === "fullscreen"
+ : this.args.composeState === "fullscreen"
? "discourse-compress"
: "discourse-expand";
}
- @discourseComputed("disableTextarea")
- showFullScreenButton(disableTextarea) {
+ get showFullScreenButton() {
if (this.site.mobileView) {
return false;
}
- return !disableTextarea;
+ return !this.args.disableTextarea;
}
<template>
@@ -61,7 +50,7 @@ export default class ComposerToggles extends Component {
{{#if this.site.mobileView}}
<DButton
@icon="bars"
- @action={{this.toggleToolbar}}
+ @action={{@toggleToolbar}}
@title={{this.toggleToolbarTitle}}
@preventFocus={{true}}
class="btn-transparent toggle-toolbar btn-mini-toggle"
@@ -71,18 +60,29 @@ export default class ComposerToggles extends Component {
{{#if this.showFullScreenButton}}
<DButton
@icon={{this.fullscreenIcon}}
- @action={{this.toggleFullscreen}}
+ @action={{@toggleFullscreen}}
@title={{this.fullscreenTitle}}
class="btn-transparent toggle-fullscreen btn-mini-toggle"
/>
{{/if}}
- <DButton
- @icon={{this.toggleIcon}}
- @action={{this.toggleComposer}}
- @title={{this.toggleTitle}}
- class="btn-transparent toggler toggle-minimize btn-mini-toggle"
- />
+ {{#if this.showCollapseButton}}
+ <DButton
+ @icon="angles-down"
+ @action={{@toggleComposer}}
+ @title="composer.collapse"
+ class="btn-transparent toggler toggle-minimize btn-mini-toggle"
+ />
+ {{/if}}
+
+ {{#if @saveAndClose}}
+ <DButton
+ @icon="xmark"
+ @action={{@saveAndClose}}
+ @title="composer.save_and_close"
+ class="btn-transparent toggler toggle-save-and-close btn-mini-toggle"
+ />
+ {{/if}}
</div>
</template>
}
diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js
index 8c5c47f2c06..ab293ee34ad 100644
--- a/app/assets/javascripts/discourse/app/models/composer.js
+++ b/app/assets/javascripts/discourse/app/models/composer.js
@@ -257,6 +257,11 @@ export default class Composer extends RestModel {
return (title || "").trim() !== (original || "").trim();
}
+ @discourseComputed("replyDirty", "titleDirty", "hasMetaData")
+ anyDirty(replyDirty, titleDirty, hasMetaData) {
+ return replyDirty || titleDirty || hasMetaData;
+ }
+
@dependentKeyCompat
get categoryId() {
return this._categoryId;
diff --git a/app/assets/javascripts/discourse/app/services/composer.js b/app/assets/javascripts/discourse/app/services/composer.js
index 432e140991a..d9a696c39ff 100644
--- a/app/assets/javascripts/discourse/app/services/composer.js
+++ b/app/assets/javascripts/discourse/app/services/composer.js
@@ -641,6 +641,12 @@ export default class ComposerService extends Service {
this.set("model.showFullScreenExitPrompt", false);
}
+ @action
+ async saveAndClose(event) {
+ event?.preventDefault();
+ await this.saveAndCloseComposer();
+ }
+
@action
async cancel(event) {
event?.preventDefault();
@@ -1593,12 +1599,10 @@ export default class ComposerService extends Service {
cancelComposer(opts = {}) {
this.skipAutoSave = true;
- if (this._saveDraftDebounce) {
- cancel(this._saveDraftDebounce);
- }
+ cancel(this._saveDraftDebounce);
return new Promise((resolve) => {
- if (this.get("model.hasMetaData") || this.get("model.replyDirty")) {
+ if (this.get("model.anyDirty")) {
const overridesDraft =
this.model.composeState === Composer.OPEN &&
this.model.draftKey === opts.draftKey &&
@@ -1645,6 +1649,23 @@ export default class ComposerService extends Service {
});
}
+ saveAndCloseComposer() {
+ // Always save the draft if the user had typed something
+ // or had started setting up a title/tags/category
+ if (this.model.anyDirty) {
+ this.skipAutoSave = true;
+ this._saveDraft(true);
+ this.model.clearState();
+ this.close();
+ this.appEvents.trigger("composer:cancelled");
+ this.skipAutoSave = false;
+ return true;
+ } else {
+ // Otherwise just close the composer and discard any empty draft
+ return this.cancelComposer();
+ }
+ }
+
unshrink() {
this.model.set("composeState", Composer.OPEN);
document.documentElement.style.setProperty(
@@ -1657,7 +1678,9 @@ export default class ComposerService extends Service {
this.collapse();
}
- _saveDraft() {
+ _saveDraft(showToast = false) {
+ cancel(this._saveDraftDebounce);
+
if (!this.model) {
return;
}
@@ -1675,6 +1698,14 @@ export default class ComposerService extends Service {
}
this._saveDraftPromise = this.model.saveDraft().finally(() => {
+ if (showToast) {
+ this.toasts.success({
+ duration: "short",
+ data: {
+ message: i18n("composer.draft_saved"),
+ },
+ });
+ }
this._lastDraftSaved = Date.now();
this._saveDraftPromise = null;
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/assets-version-test.js b/app/assets/javascripts/discourse/tests/acceptance/assets-version-test.js
index c402337b99f..0937ab8370e 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/assets-version-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/assets-version-test.js
@@ -49,7 +49,7 @@ acceptance("Software update refresh", function (needs) {
redirectStub.resetHistory();
await visit("/");
- await click(".save-or-cancel .cancel");
+ await click(".discard .discard-button");
await click(".nav-item_hot a");
assert.true(
redirectStub.calledWith("/hot"),
diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
index 8e7cd500d72..7864466f1c0 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
@@ -127,7 +127,7 @@ import { i18n } from "discourse-i18n";
);
await fillIn(".d-editor-input", "");
- await click(".btn.cancel");
+ await click("#reply-control .discard .discard-button");
assert.strictEqual(
document.documentElement.style.getPropertyValue("--composer-height"),
"",
@@ -227,7 +227,7 @@ import { i18n } from "discourse-i18n";
"supports keyboard shortcuts"
);
- await click("#reply-control button.cancel");
+ await click("#reply-control .discard .discard-button");
assert.dom(".d-modal").exists("pops up a confirmation dialog");
await click(".d-modal__footer .discard-draft");
@@ -502,7 +502,7 @@ import { i18n } from "discourse-i18n";
assert.verifySteps(["saveDraft"], "first draft is auto saved");
- await click("#reply-control button.cancel");
+ await click("#reply-control .discard .discard-button");
assert
.dom(".discard-draft-modal.modal")
@@ -863,7 +863,7 @@ import { i18n } from "discourse-i18n";
await visit("/t/topic-with-whisper/54081");
await click(".topic-post[data-post-number='3'] button.reply");
- await click("#reply-control .save-or-cancel button.cancel");
+ await click("#reply-control .discard .discard-button");
await click(".timeline-footer-controls button.create");
await click(".reply-details summary div");
assert
@@ -993,7 +993,7 @@ import { i18n } from "discourse-i18n";
const privateMessageUsers = selectKit("#private-message-users");
assert.strictEqual(privateMessageUsers.header().value(), "charlie");
- await click(".submit-panel .cancel");
+ await click("#reply-control .discard .discard-button");
assert.dom(".d-editor-input").doesNotExist();
});
@@ -1106,7 +1106,7 @@ import { i18n } from "discourse-i18n";
await click("#create-topic");
await fillIn("#reply-title", "Something");
await fillIn(".d-editor-input", "Something");
- await click(".save-or-cancel .cancel");
+ await click(".discard .discard-button");
assert.dom(".discard-draft-modal .save-draft").doesNotExist();
});
@@ -1116,7 +1116,7 @@ import { i18n } from "discourse-i18n";
await fillIn(".d-editor-input", "[quote]some quote[/quote]");
- await click(".save-or-cancel .cancel");
+ await click(".discard .discard-button");
assert.dom(".discard-draft-modal .save-draft").exists();
});
@@ -1126,7 +1126,7 @@ import { i18n } from "discourse-i18n";
await fillIn(".d-editor-input", "[quote]some quote[/quote]");
- await click(".save-or-cancel .cancel");
+ await click(".discard .discard-button");
assert.dom(".discard-draft-modal .save-draft").exists();
await triggerKeyEvent(
diff --git a/app/assets/stylesheets/common/base/compose.scss b/app/assets/stylesheets/common/base/compose.scss
index 4cdeacb8ebf..61dcc64c09e 100644
--- a/app/assets/stylesheets/common/base/compose.scss
+++ b/app/assets/stylesheets/common/base/compose.scss
@@ -537,7 +537,7 @@ html.composer-open:not(.has-full-page-chat) {
display: flex;
margin-left: 1em;
line-height: normal;
- color: var(--primary-high);
+ color: var(--accent-color);
transition: color 250ms;
padding: 0;
@@ -566,6 +566,26 @@ html.composer-open:not(.has-full-page-chat) {
}
}
+ .discard {
+ @include viewport.from(sm) {
+ margin-left: auto;
+ flex: 1;
+ text-align: right;
+ }
+ }
+
+ .discard-button {
+ color: var(--danger);
+
+ @include viewport.until(sm) {
+ .d-icon {
+ font-size: var(--font-up-2);
+ color: var(--primary-medium);
+ padding: 0.35em;
+ }
+ }
+ }
+
#draft-status,
#file-uploading {
color: var(--primary-high);
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index d5c84cb39a9..44d78feb6de 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2969,6 +2969,9 @@ en:
create_shared_draft: "Create Shared Draft"
edit_shared_draft: "Edit Shared Draft"
title: "Or press %{modifier}Enter"
+ save_and_close: "Save and close"
+ discard: "Discard"
+ draft_saved: "Draft saved!"
users_placeholder: "Add users or groups"
title_placeholder: "What is this discussion about in one brief sentence?"
@@ -3026,14 +3029,15 @@ en:
list_item: "List item"
toggle_direction: "Toggle direction"
help: "Markdown Editing Help"
- collapse: "minimize the composer panel"
- open: "open the composer panel"
- abandon: "close composer and discard draft"
- enter_fullscreen: "enter fullscreen composer"
- exit_fullscreen: "exit fullscreen composer"
+ collapse: "Minimize the composer panel"
+ open: "Open the composer panel"
+ abandon: "Close composer and discard draft"
+ enter_fullscreen: "Enter fullscreen composer"
+ exit_fullscreen: "Exit fullscreen composer"
exit_fullscreen_prompt: "Press <kbd>ESC</kbd> to exit full screen"
- show_toolbar: "show composer toolbar"
- hide_toolbar: "hide composer toolbar"
+ show_toolbar: "Show composer toolbar"
+ hide_toolbar: "Hide composer toolbar"
+ peek_mode_toggle: "Toggle peek mode"
modal_ok: "OK"
cant_send_pm: "Sorry, you can't send a message to %{username}."
create_message_error: "Sorry, there was an error creating that message. Please try again."
diff --git a/spec/system/composer/category_templates_spec.rb b/spec/system/composer/category_templates_spec.rb
index 7869c5d6e89..e30cf510959 100644
--- a/spec/system/composer/category_templates_spec.rb
+++ b/spec/system/composer/category_templates_spec.rb
@@ -222,7 +222,7 @@ describe "Composer Form Templates", type: :system do
it "does not show the modal if there is no draft on a topic without a template" do
category_page.visit(category_no_template)
category_page.new_topic_button.click
- composer.close
+ composer.discard
expect(composer).to be_closed
end
@@ -230,7 +230,7 @@ describe "Composer Form Templates", type: :system do
category_page.visit(category_no_template)
category_page.new_topic_button.click
composer.fill_content("abc")
- composer.close
+ composer.discard
expect(composer).to be_opened
expect(composer).to have_discard_draft_modal
end
@@ -238,7 +238,7 @@ describe "Composer Form Templates", type: :system do
it "does not show the modal if there is no draft on a topic with a topic template" do
category_page.visit(category_topic_template)
category_page.new_topic_button.click
- composer.close
+ composer.discard
expect(composer).to be_closed
end
@@ -246,7 +246,7 @@ describe "Composer Form Templates", type: :system do
category_page.visit(category_topic_template)
category_page.new_topic_button.click
composer.append_content(" some more content")
- composer.close
+ composer.discard
expect(composer).to be_opened
expect(composer).to have_discard_draft_modal
end
@@ -254,7 +254,7 @@ describe "Composer Form Templates", type: :system do
it "does not show the modal if on a topic with a form template" do
category_page.visit(category_with_template_1)
category_page.new_topic_button.click
- composer.close
+ composer.discard
expect(composer).to be_closed
end
@@ -274,7 +274,7 @@ describe "Composer Form Templates", type: :system do
it "does not show the modal if there is no draft" do
category_page.visit(default_category)
category_page.new_topic_button.click
- composer.close
+ composer.discard
expect(composer).to be_closed
end
@@ -282,7 +282,7 @@ describe "Composer Form Templates", type: :system do
category_page.visit(default_category)
category_page.new_topic_button.click
composer.append_content(" some more content")
- composer.close
+ composer.discard
expect(composer).to be_opened
expect(composer).to have_discard_draft_modal
end
diff --git a/spec/system/composer/discard_draft_spec.rb b/spec/system/composer/discard_draft_spec.rb
deleted file mode 100644
index da7e3645166..00000000000
--- a/spec/system/composer/discard_draft_spec.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-# frozen_string_literal: true
-
-describe "Composer - discard draft modal", type: :system do
- fab!(:topic)
- fab!(:admin)
-
- let(:topic_page) { PageObjects::Pages::Topic.new }
- let(:composer) { PageObjects::Components::Composer.new }
- let(:discard_draft_modal) { PageObjects::Modals::DiscardDraft.new }
-
- before { sign_in(admin) }
-
- context "when editing different post" do
- fab!(:post_1) { Fabricate(:post, topic:, user: admin) }
- fab!(:post_2) { Fabricate(:post, topic:, user: admin) }
-
- it "shows the discard modal when there are changes in the composer" do
- topic_page.visit_topic(post_1.topic)
- topic_page.click_post_action_button(post_1, :edit)
- composer.fill_content("a b c d e f g")
- composer.minimize
-
- topic_page.click_post_action_button(post_2, :edit)
-
- expect(discard_draft_modal).to be_open
- end
-
- it "doesn't show the discard modal when there are no changes in the composer" do
- topic_page.visit_topic(post_1.topic)
- topic_page.click_post_action_button(post_1, :edit)
- composer.minimize
-
- topic_page.click_post_action_button(post_2, :edit)
-
- expect(discard_draft_modal).to be_closed
- expect(composer).to be_opened
- end
- end
-
- context "when editing the same post" do
- fab!(:post_1) { Fabricate(:post, topic:, user: admin) }
-
- it "doesn’t show the discard modal even if there are changes in the composer" do
- topic_page.visit_topic(post_1.topic)
- topic_page.click_post_action_button(post_1, :edit)
- composer.fill_content("a b c d e f g")
- composer.minimize
-
- topic_page.click_post_action_button(post_1, :edit)
-
- expect(discard_draft_modal).to be_closed
- expect(composer).to be_opened
- expect(composer).to have_content("a b c d e f g")
-
- composer.minimize
- expect(composer).to be_minimized
-
- topic_page.click_post_action_button(post_1, :edit)
-
- expect(discard_draft_modal).to be_closed
- expect(composer).to be_opened
- end
-
- it "doesn’t show the discard modal when there are no changes in the composer" do
- topic_page.visit_topic(post_1.topic)
- topic_page.click_post_action_button(post_1, :edit)
- composer.minimize
-
- topic_page.click_post_action_button(post_1, :edit)
-
- expect(discard_draft_modal).to be_closed
- expect(composer).to be_opened
- end
- end
-
- context "when clicking abandon draft" do
- let(:dialog) { PageObjects::Components::Dialog.new }
-
- before { Jobs.run_immediately! }
-
- it "destroys draft" do
- visit "/new-topic"
-
- composer.fill_title("this is a test topic")
- composer.fill_content("a b c d e f g")
-
- wait_for(timeout: 5) { Draft.count == 1 }
-
- composer.close
-
- expect(discard_draft_modal).to be_open
- discard_draft_modal.click_discard
-
- wait_for(timeout: 5) { Draft.count == 0 }
- end
- end
-end
diff --git a/spec/system/composer/drafts_spec.rb b/spec/system/composer/drafts_spec.rb
new file mode 100644
index 00000000000..8cfe5c37215
--- /dev/null
+++ b/spec/system/composer/drafts_spec.rb
@@ -0,0 +1,164 @@
+# frozen_string_literal: true
+
+describe "Composer - Drafts", type: :system do
+ fab!(:topic)
+ fab!(:current_user, :admin)
+
+ let(:toasts) { PageObjects::Components::Toasts.new }
+ let(:topic_page) { PageObjects::Pages::Topic.new }
+ let(:composer) { PageObjects::Components::Composer.new }
+ let(:discard_draft_modal) { PageObjects::Modals::DiscardDraft.new }
+
+ before { sign_in(current_user) }
+
+ context "when clicking X (save and close)" do
+ it "saves the draft and shows a toast" do
+ visit "/new-topic"
+
+ expect(composer).to be_opened
+ composer.fill_title("this is a test topic")
+ composer.fill_content("a b c d e f g")
+ composer.close
+
+ expect(toasts).to have_success(I18n.t("js.composer.draft_saved"))
+ expect(Draft.where(user: current_user).count).to eq(1)
+ end
+
+ context "when only a title and category is specified" do
+ fab!(:category_1, :category)
+ fab!(:category_2, :category)
+
+ it "saves the draft and shows a toast" do
+ visit "/new-topic"
+
+ expect(composer).to be_opened
+ composer.fill_title("this is a test topic")
+ composer.switch_category(category_1.name)
+ composer.close
+
+ expect(toasts).to have_success(I18n.t("js.composer.draft_saved"))
+ expect(Draft.where(user: current_user).count).to eq(1)
+ end
+ end
+ end
+
+ context "when clicking discard" do
+ let(:dialog) { PageObjects::Components::Dialog.new }
+
+ before { Jobs.run_immediately! }
+
+ it "does not show confirmation if there is no user input in the composer" do
+ visit "/new-topic"
+
+ expect(composer).to be_opened
+ composer.discard
+
+ expect(discard_draft_modal).to be_closed
+ expect(composer).to be_closed
+ end
+
+ it "destroys draft after discard confirmation" do
+ visit "/new-topic"
+
+ composer.fill_title("this is a test topic")
+ composer.fill_content("a b c d e f g")
+
+ try_until_success { expect(Draft.where(user: current_user).count).to eq(1) }
+
+ composer.discard
+
+ expect(discard_draft_modal).to be_open
+ discard_draft_modal.click_discard
+
+ expect(discard_draft_modal).to be_closed
+ expect(composer).to be_closed
+
+ try_until_success { expect(Draft.where(user: current_user).count).to eq(0) }
+ end
+
+ context "when only a title and category is specified" do
+ fab!(:category_1, :category)
+ fab!(:category_2, :category)
+
+ it "shows discard confirmation and allows saving the draft" do
+ visit "/new-topic"
+
+ expect(composer).to be_opened
+ composer.fill_title("this is a test topic")
+ composer.switch_category(category_1.name)
+ composer.discard
+
+ expect(discard_draft_modal).to be_open
+ discard_draft_modal.click_save
+
+ expect(discard_draft_modal).to be_closed
+ expect(composer).to be_closed
+
+ expect(Draft.where(user: current_user).count).to eq(1)
+ end
+ end
+ end
+
+ context "when editing different post" do
+ fab!(:post_1) { Fabricate(:post, topic:, user: current_user) }
+ fab!(:post_2) { Fabricate(:post, topic:, user: current_user) }
+
+ it "shows the discard modal when there are changes in the composer" do
+ topic_page.visit_topic(post_1.topic)
+ topic_page.click_post_action_button(post_1, :edit)
+ composer.fill_content("a b c d e f g")
+ composer.minimize
+
+ topic_page.click_post_action_button(post_2, :edit)
+
+ expect(discard_draft_modal).to be_open
+ end
+
+ it "doesn't show the discard modal when there are no changes in the composer" do
+ topic_page.visit_topic(post_1.topic)
+ topic_page.click_post_action_button(post_1, :edit)
+ composer.minimize
+
+ topic_page.click_post_action_button(post_2, :edit)
+
+ expect(discard_draft_modal).to be_closed
+ expect(composer).to be_opened
+ end
+ end
+
+ context "when editing the same post" do
+ fab!(:post_1) { Fabricate(:post, topic:, user: current_user) }
+
+ it "doesn’t show the discard modal even if there are changes in the composer" do
+ topic_page.visit_topic(post_1.topic)
+ topic_page.click_post_action_button(post_1, :edit)
+ composer.fill_content("a b c d e f g")
+ composer.minimize
+
+ topic_page.click_post_action_button(post_1, :edit)
+
+ expect(discard_draft_modal).to be_closed
+ expect(composer).to be_opened
+ expect(composer).to have_content("a b c d e f g")
+
+ composer.minimize
+ expect(composer).to be_minimized
+
+ topic_page.click_post_action_button(post_1, :edit)
+
+ expect(discard_draft_modal).to be_closed
+ expect(composer).to be_opened
+ end
+
+ it "doesn’t show the discard modal when there are no changes in the composer" do
+ topic_page.visit_topic(post_1.topic)
+ topic_page.click_post_action_button(post_1, :edit)
+ composer.minimize
+
+ topic_page.click_post_action_button(post_1, :edit)
+
+ expect(discard_draft_modal).to be_closed
+ expect(composer).to be_opened
+ end
+ end
+end
diff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rb
index 6f7c6606837..2589830aef9 100644
--- a/spec/system/page_objects/components/composer.rb
+++ b/spec/system/page_objects/components/composer.rb
@@ -312,8 +312,12 @@ module PageObjects
find("#{COMPOSER_ID} .save-or-cancel .create").click
end
+ def discard
+ find("#{COMPOSER_ID} .discard .discard-button").click
+ end
+
def close
- find("#{COMPOSER_ID} .save-or-cancel .cancel").click
+ find("#{COMPOSER_ID} .toggle-save-and-close").click
end
def has_no_in_progress_uploads?
diff --git a/themes/horizon/javascripts/discourse/components/composer-peek-mode-toggle.gjs b/themes/horizon/javascripts/discourse/components/composer-peek-mode-toggle.gjs
index 8dab13dab71..c7e680ed2e0 100644
--- a/themes/horizon/javascripts/discourse/components/composer-peek-mode-toggle.gjs
+++ b/themes/horizon/javascripts/discourse/components/composer-peek-mode-toggle.gjs
@@ -31,6 +31,7 @@ export default class ComposerPeekModeToggle extends Component {
@action={{this.togglePeekMode}}
@preventFocus={{true}}
@icon="discourse-sidebar"
+ @title="composer.peek_mode_toggle"
class="btn-mini-toggle no-text peek-mode-toggle btn-transparent"
/>
</template>