A platform for community discussion. Free, open, simple.
FEATURE: Show event description in calendar popup (#39076)
Régis HANOL40ea3cfe1ae7
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/description.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/description.gjsindex c83c1a55dbe..701a139cbb0 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/description.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/description.gjs@@ -1,11 +1,70 @@-import CookText from "discourse/components/cook-text";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { on } from "@ember/modifier";+import { modifier } from "ember-modifier";+import icon from "discourse/helpers/d-icon";+import { i18n } from "discourse-i18n";-const DiscoursePostEventDescription = <template>- {{#if @description}}- <section class="event__section event-description">- <CookText @rawText={{@description}} />- </section>- {{/if}}-</template>;+export default class DiscoursePostEventDescription extends Component {+ @tracked expanded = false;+ @tracked overflowing = false;-export default DiscoursePostEventDescription;+ detectOverflow = modifier((element) => {+ const check = () => {+ const textEl = element.querySelector(".event-description__text");+ if (textEl) {+ this.overflowing = textEl.scrollHeight > textEl.clientHeight;+ }+ };++ const observer = new ResizeObserver(check);+ observer.observe(element);++ return () => observer.disconnect();+ });++ toggle = (event) => {+ event.preventDefault();+ this.expanded = !this.expanded;+ };++ get showToggle() {+ return this.clamp && (this.overflowing || this.expanded);+ }++ get clamp() {+ return this.args.clamp ?? false;+ }++ get toggleLabel() {+ return this.expanded+ ? i18n("discourse_post_event.event_description.show_less")+ : i18n("discourse_post_event.event_description.show_more");+ }++ <template>+ {{#if @description}}+ <section+ class="event__section event-description+ {{if this.clamp 'is-clamped'}}+ {{if this.expanded 'is-expanded'}}"+ >+ {{icon "file-lines"}}++ <div+ class="event-description__content"+ {{(if this.clamp this.detectOverflow)}}+ >+ <p class="event-description__text">{{@description}}</p>+ {{#if this.showToggle}}+ <a+ href+ class="event-description__toggle"+ {{on "click" this.toggle}}+ >{{this.toggleLabel}}</a>+ {{/if}}+ </div>+ </section>+ {{/if}}+ </template>+}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjsindex 794b5dcd34b..fa686be941d 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs@@ -66,6 +66,10 @@ export default class DiscoursePostEvent extends Component {}}+ get clampDescription() {+ return this.args.clampDescription ?? false;+ }+get withDescription() {return this.args.withDescription ?? true;}@@ -203,7 +207,9 @@ export default class DiscoursePostEvent extends Component {Section=(component InfoSection event=event)Url=(component Url url=event.url)Description=(component- Description description=event.description+ Description+ description=event.description+ clamp=this.clampDescription)Location=(component Location location=event.location)Dates=(component@@ -235,7 +241,10 @@ export default class DiscoursePostEvent extends Component {<Invitees @event={{event}} />{{#if this.withDescription}}- <Description @description={{event.description}} />+ <Description+ @description={{event.description}}+ @clamp={{this.clampDescription}}+ />{{/if}}{{#if @event.canUpdateAttendance}}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjsindex 12309c3329e..135f676fb65 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/full-calendar.gjs@@ -21,7 +21,8 @@ const PostEventMenu = <template>@linkToPost={{true}}@event={{@data.event}}@onClose={{@data.onClose}}- @withDescription={{false}}+ @withDescription={{true}}+ @clampDescription={{true}}/></template>;diff --git a/plugins/discourse-calendar/assets/stylesheets/common/discourse-calendar.scss b/plugins/discourse-calendar/assets/stylesheets/common/discourse-calendar.scssindex e5d8f2b705d..3a319194d3f 100644--- a/plugins/discourse-calendar/assets/stylesheets/common/discourse-calendar.scss+++ b/plugins/discourse-calendar/assets/stylesheets/common/discourse-calendar.scss@@ -283,8 +283,8 @@ a.holiday {}.discourse-post-event-loader {- width: 200px;- height: 100px;+ width: 100%;+ min-height: 200px;display: flex;align-items: center;justify-content: center;diff --git a/plugins/discourse-calendar/assets/stylesheets/common/discourse-post-event.scss b/plugins/discourse-calendar/assets/stylesheets/common/discourse-post-event.scssindex de602e1183d..701b153d29f 100644--- a/plugins/discourse-calendar/assets/stylesheets/common/discourse-post-event.scss+++ b/plugins/discourse-calendar/assets/stylesheets/common/discourse-post-event.scss@@ -358,10 +358,7 @@ $show-interested: inherit;margin: 0;}- .event-description {- display: flex;- }-+ .event-description,.event-location,.event-url,.event-dates,@@ -385,6 +382,33 @@ $show-interested: inherit;}}+ .event-description {+ align-items: start;+ padding-right: 2em;++ > .d-icon {+ margin-top: 0.25em;+ }++ .event-description__text {+ text-align: justify;+ }++ &.is-clamped .event-description__text {+ @include line-clamp(3);+ }++ &.is-clamped.is-expanded .event-description__text {+ -webkit-line-clamp: unset;+ }++ .event-description__toggle {+ font-size: var(--font-down-1);+ margin-top: 0.25em;+ cursor: pointer;+ }+ }+.event-recurrence {color: var(--primary-medium);padding-top: 0;diff --git a/plugins/discourse-calendar/config/locales/client.en.yml b/plugins/discourse-calendar/config/locales/client.en.ymlindex c259538d440..29d2894d1d9 100644--- a/plugins/discourse-calendar/config/locales/client.en.yml+++ b/plugins/discourse-calendar/config/locales/client.en.yml@@ -334,6 +334,9 @@ en:invite_user_notification: "%{username} %{description}"invite_user_predefined_attendance_notification: "%{username} has automatically set your attendance and invited you to %{eventName}"an_event: "an event"+ event_description:+ show_more: "Show more"+ show_less: "Show less"edit_reason: "Event updated"edit_reason_closed: "Event closed"edit_reason_opened: "Event opened"diff --git a/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/post_event.rb b/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/post_event.rbindex 7e21e0f1a2b..2ab611094da 100644--- a/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/post_event.rb+++ b/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/post_event.rb@@ -30,6 +30,31 @@ module PageObjectshas_css?(".event-description", text:)end+ def has_no_description?+ has_no_css?(".event-description")+ end++ def has_description_toggle?+ has_css?(".event-description__toggle")+ end++ def has_no_description_toggle?+ has_no_css?(".event-description__toggle")+ end++ def click_description_toggle+ find(".event-description__toggle").click+ self+ end++ def has_description_clamped?+ has_css?(".event-description.is-clamped:not(.is-expanded)")+ end++ def has_description_expanded?+ has_css?(".event-description.is-clamped.is-expanded")+ end+def closehas_css?(".discourse-post-event .status-and-creators .status:not(.closed)")open_more_menudiff --git a/plugins/discourse-calendar/spec/system/post_event_spec.rb b/plugins/discourse-calendar/spec/system/post_event_spec.rbindex b428d27013c..dad04aea914 100644--- a/plugins/discourse-calendar/spec/system/post_event_spec.rb+++ b/plugins/discourse-calendar/spec/system/post_event_spec.rb@@ -51,7 +51,18 @@ describe "Post event" doexpect(post_event_page).to have_description(%r{this is a test description\s+and a link http://example.com},)- expect(page).to have_css(".event-description a[href='http://example.com']")+ end++ it "shows the full description without a toggle in the topic view" do+ title = "Event with full description"+ description = "A short event description"+ raw = "[event start='2222-02-22 14:22']\n#{description}\n[/event]"+ post = PostCreator.create(admin, title:, raw:)++ visit(post.topic.url)++ expect(post_event_page).to have_description(description)+ expect(post_event_page).to have_no_description_toggleendit "correctly builds a multiline description" dodiff --git a/plugins/discourse-calendar/spec/system/upcoming_events_spec.rb b/plugins/discourse-calendar/spec/system/upcoming_events_spec.rbindex 17ef6b7ac55..19f250e7a21 100644--- a/plugins/discourse-calendar/spec/system/upcoming_events_spec.rb+++ b/plugins/discourse-calendar/spec/system/upcoming_events_spec.rb@@ -32,6 +32,54 @@ describe "Upcoming Events" doendend+ describe "event description in popup" do+ let(:post_event_page) { PageObjects::Pages::DiscourseCalendar::PostEvent.new }++ it "shows clamped description with expand toggle", time: Time.utc(2025, 9, 10, 12, 0) do+ long_description =+ "Join us for a <b>great</b> event :tada: with **bold text** and more details! " * 10+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "Event with long description",+ raw:+ "[event start=\"2025-09-11 08:05\" end=\"2025-09-11 10:05\"]\n#{long_description}\n[/event]",+ )++ upcoming_events.visit+ upcoming_events.open_year_view++ find("a", text: "Event with long description").click++ expect(post_event_page).to have_description_clamped+ expect(post_event_page).to have_description(+ "Join us for a great event with bold text and more details!",+ )+ expect(post_event_page).to have_description_toggle++ post_event_page.click_description_toggle++ expect(post_event_page).to have_description_expanded+ end++ it "shows description without toggle for short text", time: Time.utc(2025, 9, 10, 12, 0) do+ create_post(+ user: admin,+ category: Fabricate(:category),+ title: "Event with short description",+ raw: "[event start=\"2025-09-11 08:05\" end=\"2025-09-11 10:05\"]\nBrief sync.\n[/event]",+ )++ upcoming_events.visit+ upcoming_events.open_year_view++ find("a", text: "Event with short description").click++ expect(post_event_page).to have_description("Brief sync.")+ expect(post_event_page).to have_no_description_toggle+ end+ end+describe "event display and formatting" dobefore { admin.user_option.update!(timezone: "America/New_York") }