FEATURE: use default calendar to save events (#178)

FEATURE: use default calendar to save events (#178)

Follow up of FEATURE: save local date to calendar by lis2 · Pull Request #14486 · discourse/discourse · GitHub

Use core modal function for calendar

diff --git a/assets/javascripts/discourse/widgets/discourse-post-event.js.es6 b/assets/javascripts/discourse/widgets/discourse-post-event.js.es6
index 8478ce6..661c736 100644
--- a/assets/javascripts/discourse/widgets/discourse-post-event.js.es6
+++ b/assets/javascripts/discourse/widgets/discourse-post-event.js.es6
@@ -138,11 +138,23 @@ export default createWidget("discourse-post-event", {
   },
 
   addToCalendar() {
-    const link = getURL(
-      `/discourse-post-event/events.ics?post_id=${this.state.eventModel.id}`
-    );
+    const event = this.state.eventModel;
+    // TODO with Discourse 2.8
+    // * Remove old ics logic and corresponding backend logic
+    if (this.attrs.api.downloadCalendar) {
+      this.attrs.api.downloadCalendar(event.name || event.post.topic.title, [
+        {
+          startsAt: event.starts_at,
+          endsAt: event.ends_at,
+        },
+      ]);
+    } else {
+      const link = getURL(
+        `/discourse-post-event/events.ics?post_id=${this.state.eventModel.id}`
+      );
 
-    window.open(link, "_blank", "noopener");
+      window.open(link, "_blank", "noopener");
+    }
   },
 
   transform() {
diff --git a/assets/javascripts/initializers/discourse-post-event-decorator.js.es6 b/assets/javascripts/initializers/discourse-post-event-decorator.js.es6
index a7ca526..dd477a9 100644
--- a/assets/javascripts/initializers/discourse-post-event-decorator.js.es6
+++ b/assets/javascripts/initializers/discourse-post-event-decorator.js.es6
@@ -149,6 +149,7 @@ function _attachWidget(api, cooked, eventModel) {
           eventModel,
           widgetHeight,
           localDates: $(result.string).html(),
+          api,
         });
 
         glue.appendTo(glueContainer);
@@ -171,6 +172,7 @@ function _attachWidget(api, cooked, eventModel) {
         eventModel,
         widgetHeight,
         localDates,
+        api,
       });
 
       glue.appendTo(glueContainer);

GitHub sha: 565214b98ab2e7db1bb40e7b3e806afb723d9d7a

This commit appears in #178 which was approved by OsamaSayegh. It was merged by lis2.