diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
index be2597e6f77..3e3268a4877 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
@@ -5,7 +5,6 @@ import { tracked } from "@glimmer/tracking";
import { cancel, next } from "@ember/runloop";
import { cloneJSON } from "discourse-common/lib/object";
import { chatComposerButtons } from "discourse/plugins/chat/discourse/lib/chat-composer-buttons";
-import showModal from "discourse/lib/show-modal";
import TextareaInteractor from "discourse/plugins/chat/discourse/lib/textarea-interactor";
import { getOwner } from "discourse-common/lib/get-owner";
import userSearch from "discourse/lib/user-search";
@@ -166,13 +165,19 @@ export default class ChatComposer extends Component {
@action
insertDiscourseLocalDate() {
- showModal("discourse-local-dates-create-modal").setProperties({
- insertDate: (markup) => {
- this.composer.textarea.addText(
- this.composer.textarea.getSelected(),
- markup
- );
- this.composer.focus();
+ // JIT import because local-dates isn't necessarily enabled
+ const LocalDatesCreateModal =
+ require("discourse/plugins/discourse-local-dates/discourse/components/modal/local-dates-create").default;
+
+ this.modal.show(LocalDatesCreateModal, {
+ model: {
+ insertDate: (markup) => {
+ this.composer.textarea.addText(
+ this.composer.textarea.getSelected(),
+ markup
+ );
+ this.composer.focus();
+ },
},
});
}
diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/components/modal/local-dates-create.hbs b/plugins/discourse-local-dates/assets/javascripts/discourse/components/modal/local-dates-create.hbs
new file mode 100644
index 00000000000..1175375e5e9
--- /dev/null
+++ b/plugins/discourse-local-dates/assets/javascripts/discourse/components/modal/local-dates-create.hbs
@@ -0,0 +1,200 @@
+
+ <:body>
+
+
+
+ <:footer>
+
+ {{#if this.isValid}}
+
+ {{/if}}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js b/plugins/discourse-local-dates/assets/javascripts/discourse/components/modal/local-dates-create.js
similarity index 97%
rename from plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js
rename to plugins/discourse-local-dates/assets/javascripts/discourse/components/modal/local-dates-create.js
index ce019c9ae80..ddf42ef1951 100644
--- a/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js
+++ b/plugins/discourse-local-dates/assets/javascripts/discourse/components/modal/local-dates-create.js
@@ -10,7 +10,6 @@ import { cookAsync } from "discourse/lib/text";
import { notEmpty } from "@ember/object/computed";
import { propertyNotEqual } from "discourse/lib/computed";
import { schedule } from "@ember/runloop";
-import { getOwner } from "discourse-common/lib/get-owner";
import { applyLocalDates } from "discourse/lib/local-dates";
import generateDateMarkup from "discourse/plugins/discourse-local-dates/lib/local-date-markup-generator";
@@ -369,17 +368,13 @@ export default Component.extend({
const markup = this.markup;
if (markup) {
- this._closeModal();
- this.insertDate(markup);
+ this.closeModal();
+ this.model.insertDate(markup);
}
},
@action
cancel() {
- this._closeModal();
- },
-
- _closeModal() {
- getOwner(this).lookup("service:modal").close();
+ this.closeModal();
},
});
diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/controllers/discourse-local-dates-create-modal.js b/plugins/discourse-local-dates/assets/javascripts/discourse/controllers/discourse-local-dates-create-modal.js
deleted file mode 100644
index a27b641a9bc..00000000000
--- a/plugins/discourse-local-dates/assets/javascripts/discourse/controllers/discourse-local-dates-create-modal.js
+++ /dev/null
@@ -1,21 +0,0 @@
-import Controller from "@ember/controller";
-import ModalFunctionality from "discourse/mixins/modal-functionality";
-import { schedule } from "@ember/runloop";
-
-export default Controller.extend(ModalFunctionality, {
- onShow() {
- schedule("afterRender", () => {
- const fromButton = document.getElementById("from-date-time");
- fromButton && fromButton.focus();
- });
- },
-
- onClose() {
- schedule("afterRender", () => {
- const localDatesBtn = document.querySelector(
- ".d-editor-button-bar .local-dates.btn"
- );
- localDatesBtn && localDatesBtn.focus();
- });
- },
-});
diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs b/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs
deleted file mode 100644
index 068507e1fac..00000000000
--- a/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs
+++ /dev/null
@@ -1,194 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/templates/modal/discourse-local-dates-create-modal.hbs b/plugins/discourse-local-dates/assets/javascripts/discourse/templates/modal/discourse-local-dates-create-modal.hbs
deleted file mode 100644
index 9950dca6d1f..00000000000
--- a/plugins/discourse-local-dates/assets/javascripts/discourse/templates/modal/discourse-local-dates-create-modal.hbs
+++ /dev/null
@@ -1,4 +0,0 @@
-
\ No newline at end of file
diff --git a/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js b/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js
index 55833c58203..c1389a2de35 100644
--- a/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js
+++ b/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js
@@ -2,7 +2,7 @@ import deprecated from "discourse-common/lib/deprecated";
import { getOwner } from "discourse-common/lib/get-owner";
import LocalDateBuilder from "../lib/local-date-builder";
import { withPluginApi } from "discourse/lib/plugin-api";
-import showModal from "discourse/lib/show-modal";
+import LocalDatesCreateModal from "../discourse/components/modal/local-dates-create";
import { downloadCalendar } from "discourse/lib/download-calendar";
import { renderIcon } from "discourse-common/lib/icon-library";
import I18n from "I18n";
@@ -12,6 +12,7 @@ import {
addTextDecorateCallback,
} from "discourse/lib/to-markdown";
import generateDateMarkup from "discourse/plugins/discourse-local-dates/lib/local-date-markup-generator";
+import { inject as service } from "@ember/service";
// Import applyLocalDates from discourse/lib/local-dates instead
export function applyLocalDates(dates, siteSettings) {
@@ -173,12 +174,15 @@ function initializeDiscourseLocalDates(api) {
});
api.modifyClass("component:d-editor", {
+ modal: service(),
pluginId: "discourse-local-dates",
actions: {
insertDiscourseLocalDate(toolbarEvent) {
- showModal("discourse-local-dates-create-modal").setProperties({
- insertDate: (markup) => {
- toolbarEvent.addText(markup);
+ this.modal.show(LocalDatesCreateModal, {
+ model: {
+ insertDate: (markup) => {
+ toolbarEvent.addText(markup);
+ },
},
});
},
diff --git a/plugins/discourse-local-dates/assets/stylesheets/common/discourse-local-dates.scss b/plugins/discourse-local-dates/assets/stylesheets/common/discourse-local-dates.scss
index bd21f6f7616..7da460635dd 100644
--- a/plugins/discourse-local-dates/assets/stylesheets/common/discourse-local-dates.scss
+++ b/plugins/discourse-local-dates/assets/stylesheets/common/discourse-local-dates.scss
@@ -48,7 +48,7 @@ div[data-tippy-root] {
}
}
-.discourse-local-dates-create-modal-footer {
+.discourse-local-dates-create-modal .modal-footer {
display: flex;
align-items: center;
justify-content: flex-start;
@@ -69,6 +69,7 @@ div[data-tippy-root] {
display: flex;
flex-direction: row;
padding: 0.5em;
+ overflow: auto;
.form {
flex: 1 0 0px;