DEV: Add toolbar button when chat in installed (#14422)

DEV: Add toolbar button when chat in installed (#14422)

diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js.es6 b/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js.es6
index 454bf9e..ad7c073 100644
--- a/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js.es6
+++ b/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js.es6
@@ -357,7 +357,7 @@ export default Component.extend({
 
       if (markup) {
         this._closeModal();
-        this.toolbarEvent.addText(markup);
+        this.insertDate(markup);
       }
     },
 
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
index b5f390f..611be03 100644
--- 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
@@ -1 +1 @@
-{{discourse-local-dates-create-form config=config toolbarEvent=toolbarEvent}}
+{{discourse-local-dates-create-form config=config insertDate=insertDate}}
diff --git a/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6 b/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6
index dad88fb..9dc258f 100644
--- a/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6
+++ b/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6
@@ -73,6 +73,28 @@ function _rangeElements(element) {
 
 function initializeDiscourseLocalDates(api) {
   const siteSettings = api.container.lookup("site-settings:main");
+  const chat = api.container.lookup("service:chat");
+
+  if (chat) {
+    chat.addToolbarButton({
+      title: "discourse_local_dates.title",
+      id: "local-dates",
+      icon: "calendar-alt",
+      action: "insertDiscourseLocalDate",
+    });
+
+    api.modifyClass("component:chat-composer", {
+      pluginId: "discourse-local-dates",
+      actions: {
+        insertDiscourseLocalDate() {
+          const insertDate = this.addText.bind(this);
+          showModal("discourse-local-dates-create-modal").setProperties({
+            insertDate,
+          });
+        },
+      },
+    });
+  }
 
   api.decorateCookedElement(
     (elem) => {
@@ -100,7 +122,9 @@ function initializeDiscourseLocalDates(api) {
     actions: {
       insertDiscourseLocalDate(toolbarEvent) {
         showModal("discourse-local-dates-create-modal").setProperties({
-          toolbarEvent,
+          insertDate: (markup) => {
+            toolbarEvent.addText(markup);
+          },
         });
       },
     },

GitHub sha: c9e7b64a64b1f8d2569b63c8ebaad1b93d7896ea

This commit appears in #14422 which was approved by eviltrout. It was merged by markvanlan.