mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 06:35:15 +08:00
DEV: Migrate Discard Draft to new Modal API (#22755)
Migrate discard draft to new modal API.
This commit is contained in:
parent
21dad02503
commit
d8a87792af
|
@ -0,0 +1,28 @@
|
||||||
|
<DModal @closeModal={{@closeModal}} class="discard-draft-modal">
|
||||||
|
<:body>
|
||||||
|
<div class="instructions">
|
||||||
|
{{i18n "post.cancel_composer.confirm"}}
|
||||||
|
</div>
|
||||||
|
</:body>
|
||||||
|
|
||||||
|
<:footer>
|
||||||
|
<DButton
|
||||||
|
@icon="far-trash-alt"
|
||||||
|
@label="post.cancel_composer.discard"
|
||||||
|
@class="btn-danger discard-draft"
|
||||||
|
@action={{this.discardDraft}}
|
||||||
|
/>
|
||||||
|
{{#if @model.showSaveDraftButton}}
|
||||||
|
<DButton
|
||||||
|
@label="post.cancel_composer.save_draft"
|
||||||
|
@class="save-draft"
|
||||||
|
@action={{this.saveDraftAndClose}}
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
|
<DButton
|
||||||
|
@label="post.cancel_composer.keep_editing"
|
||||||
|
@class="keep-editing"
|
||||||
|
@action={{@closeModal}}
|
||||||
|
/>
|
||||||
|
</:footer>
|
||||||
|
</DModal>
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
import Component from "@glimmer/component";
|
||||||
|
|
||||||
|
export default class DiscardDraftModal extends Component {
|
||||||
|
@action
|
||||||
|
async discardDraft() {
|
||||||
|
await this.args.model.onDestroyDraft();
|
||||||
|
this.args.closeModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
async saveDraftAndClose() {
|
||||||
|
await this.args.model.onSaveDraft();
|
||||||
|
this.args.closeModal();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,22 +0,0 @@
|
||||||
import Controller from "@ember/controller";
|
|
||||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
||||||
|
|
||||||
export default Controller.extend(ModalFunctionality, {
|
|
||||||
showSaveDraftButton: true,
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
async destroyDraft() {
|
|
||||||
await this.onDestroyDraft();
|
|
||||||
this.send("closeModal");
|
|
||||||
},
|
|
||||||
|
|
||||||
async saveDraftAndClose() {
|
|
||||||
await this.onSaveDraft();
|
|
||||||
this.send("closeModal");
|
|
||||||
},
|
|
||||||
|
|
||||||
dismissModal() {
|
|
||||||
this.send("closeModal");
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -34,6 +34,7 @@ import renderTags from "discourse/lib/render-tags";
|
||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
import { iconHTML } from "discourse-common/lib/icon-library";
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
||||||
import prepareFormTemplateData from "discourse/lib/form-template-validation";
|
import prepareFormTemplateData from "discourse/lib/form-template-validation";
|
||||||
|
import DiscardDraftModal from "discourse/components/modal/discard-draft";
|
||||||
|
|
||||||
async function loadDraft(store, opts = {}) {
|
async function loadDraft(store, opts = {}) {
|
||||||
let { draft, draftKey, draftSequence } = opts;
|
let { draft, draftKey, draftSequence } = opts;
|
||||||
|
@ -101,6 +102,7 @@ export default class ComposerController extends Controller {
|
||||||
@service store;
|
@service store;
|
||||||
@service appEvents;
|
@service appEvents;
|
||||||
@service capabilities;
|
@service capabilities;
|
||||||
|
@service modal;
|
||||||
|
|
||||||
checkedMessages = false;
|
checkedMessages = false;
|
||||||
messageCount = null;
|
messageCount = null;
|
||||||
|
@ -1498,34 +1500,32 @@ export default class ComposerController extends Controller {
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (this.get("model.hasMetaData") || this.get("model.replyDirty")) {
|
if (this.get("model.hasMetaData") || this.get("model.replyDirty")) {
|
||||||
const modal = showModal("discard-draft", {
|
|
||||||
model: this.model,
|
|
||||||
modalClass: "discard-draft-modal",
|
|
||||||
});
|
|
||||||
const overridesDraft =
|
const overridesDraft =
|
||||||
this.model.composeState === Composer.OPEN &&
|
this.model.composeState === Composer.OPEN &&
|
||||||
this.model.draftKey === opts.draftKey &&
|
this.model.draftKey === opts.draftKey &&
|
||||||
[Composer.EDIT_SHARED_DRAFT, Composer.EDIT].includes(opts.action);
|
[Composer.EDIT_SHARED_DRAFT, Composer.EDIT].includes(opts.action);
|
||||||
const showSaveDraftButton = this.model.canSaveDraft && !overridesDraft;
|
const showSaveDraftButton = this.model.canSaveDraft && !overridesDraft;
|
||||||
modal.setProperties({
|
this.modal.show(DiscardDraftModal, {
|
||||||
showSaveDraftButton,
|
model: {
|
||||||
onDestroyDraft: () => {
|
showSaveDraftButton,
|
||||||
return this.destroyDraft()
|
onDestroyDraft: () => {
|
||||||
.then(() => {
|
return this.destroyDraft()
|
||||||
this.model.clearState();
|
.then(() => {
|
||||||
this.close();
|
this.model.clearState();
|
||||||
})
|
this.close();
|
||||||
.finally(() => {
|
})
|
||||||
this.appEvents.trigger("composer:cancelled");
|
.finally(() => {
|
||||||
resolve();
|
this.appEvents.trigger("composer:cancelled");
|
||||||
});
|
resolve();
|
||||||
},
|
});
|
||||||
onSaveDraft: () => {
|
},
|
||||||
this._saveDraft();
|
onSaveDraft: () => {
|
||||||
this.model.clearState();
|
this._saveDraft();
|
||||||
this.close();
|
this.model.clearState();
|
||||||
this.appEvents.trigger("composer:cancelled");
|
this.close();
|
||||||
return resolve();
|
this.appEvents.trigger("composer:cancelled");
|
||||||
|
return resolve();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,7 +26,6 @@ const KNOWN_LEGACY_MODALS = [
|
||||||
"create-invite",
|
"create-invite",
|
||||||
"delete-topic-confirm",
|
"delete-topic-confirm",
|
||||||
"delete-topic-disallowed",
|
"delete-topic-disallowed",
|
||||||
"discard-draft",
|
|
||||||
"download-calendar",
|
"download-calendar",
|
||||||
"edit-slow-mode",
|
"edit-slow-mode",
|
||||||
"edit-topic-timer",
|
"edit-topic-timer",
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
<DModalBody @headerClass="hidden">
|
|
||||||
<div class="instructions">
|
|
||||||
{{i18n "post.cancel_composer.confirm"}}
|
|
||||||
</div>
|
|
||||||
</DModalBody>
|
|
||||||
|
|
||||||
<div class="modal-footer">
|
|
||||||
<DButton
|
|
||||||
@icon="far-trash-alt"
|
|
||||||
@label="post.cancel_composer.discard"
|
|
||||||
@class="btn-danger discard-draft"
|
|
||||||
@action={{action "destroyDraft"}}
|
|
||||||
/>
|
|
||||||
{{#if this.showSaveDraftButton}}
|
|
||||||
<DButton
|
|
||||||
@label="post.cancel_composer.save_draft"
|
|
||||||
@class="save-draft"
|
|
||||||
@action={{action "saveDraftAndClose"}}
|
|
||||||
/>
|
|
||||||
{{/if}}
|
|
||||||
<DButton
|
|
||||||
@label="post.cancel_composer.keep_editing"
|
|
||||||
@class="keep-editing"
|
|
||||||
@action={{action "dismissModal"}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
Loading…
Reference in New Issue
Block a user