UX: add a confirmation dialog for draft deletion (#11198)

This commit is contained in:
Arpit Jalan 2020-11-11 22:02:52 +05:30 committed by GitHub
parent 6ea9eb0260
commit 80759c9619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 8 deletions

View File

@ -1,3 +1,4 @@
import I18n from "I18n";
import { schedule } from "@ember/runloop";
import Component from "@ember/component";
import LoadMore from "discourse/mixins/load-more";
@ -9,6 +10,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import { getOwner } from "discourse-common/lib/get-owner";
import { observes } from "discourse-common/utils/decorators";
import { on } from "@ember/object/evented";
import bootbox from "bootbox";
export default Component.extend(LoadMore, {
_initialize: on("init", function () {
@ -94,13 +96,22 @@ export default Component.extend(LoadMore, {
removeDraft(draft) {
const stream = this.stream;
Draft.clear(draft.draft_key, draft.sequence)
.then(() => {
stream.remove(draft);
})
.catch((error) => {
popupAjaxError(error);
});
bootbox.confirm(
I18n.t("drafts.remove_confirmation"),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
Draft.clear(draft.draft_key, draft.sequence)
.then(() => {
stream.remove(draft);
})
.catch((error) => {
popupAjaxError(error);
});
}
}
);
},
loadMore() {

View File

@ -1,7 +1,7 @@
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { acceptance, visible } from "discourse/tests/helpers/qunit-helpers";
import { click } from "@ember/test-helpers";
acceptance("User Drafts", function (needs) {
@ -12,6 +12,9 @@ acceptance("User Drafts", function (needs) {
assert.ok(queryAll(".user-stream-item").length === 3, "has drafts");
await click(".user-stream-item:last-child .remove-draft");
assert.ok(visible(".bootbox"));
await click(".bootbox .btn-primary");
assert.ok(
queryAll(".user-stream-item").length === 2,
"draft removed, list length diminished by one"

View File

@ -337,6 +337,7 @@ en:
drafts:
resume: "Resume"
remove: "Remove"
remove_confirmation: "Are you sure you want to delete this draft?"
new_topic: "New topic draft"
new_private_message: "New private message draft"
topic_reply: "Draft reply"