Skip to content

A platform for community discussion. Free, open, simple.

UX: fix linked event image behavior (#41135)

Kris2115f1cac5f9
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/image.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/image.gjs
index f691f746df7..0ed9372bf94 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/image.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/image.gjs
@@ -1,9 +1,30 @@
+import { modifier } from "ember-modifier";
+import getURL from "discourse/lib/get-url";
+import lightbox from "discourse/lib/lightbox";
+
+const setupLightbox = modifier((element, _positional, { post }) => {
+ // Pass the post so the lightbox's quote-image action can build a reply
+ lightbox(element.closest(".event-image"), { post });
+
+ return () => window.pswp?.close();
+});
+
<template>
{{#if @imageUpload}}
<section class="event__section event-image">
- <a class="lightbox" href={{@imageUpload.url}}>
- <img src={{@imageUpload.url}} alt={{@alt}} />
- </a>
+ {{#if @linkToPost}}
+ <a href={{getURL @postUrl}} rel="noopener noreferrer">
+ <img src={{@imageUpload.url}} alt={{@alt}} />
+ </a>
+ {{else}}
+ <a
+ class="lightbox"
+ href={{@imageUpload.url}}
+ {{setupLightbox post=@post}}
+ >
+ <img src={{@imageUpload.url}} alt={{@alt}} />
+ </a>
+ {{/if}}
</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.gjs
index 7b2d20a3122..c505ddd7cde 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
@@ -197,6 +197,9 @@ export default class DiscoursePostEvent extends Component {
<Image
@imageUpload={{event.imageUpload}}
@alt={{this.eventName}}
+ @linkToPost={{@linkToPost}}
+ @postUrl={{event.post.url}}
+ @post={{@post}}
/>
<header class="event-header" {{this.setupMessageBus}}>
<div class="event-date">
@@ -287,7 +290,12 @@ export default class DiscoursePostEvent extends Component {
Status=(component Status event=event)
ChatChannel=(component ChatChannel event=event)
Image=(component
- Image imageUpload=event.imageUpload alt=this.eventName
+ Image
+ imageUpload=event.imageUpload
+ alt=this.eventName
+ linkToPost=@linkToPost
+ postUrl=event.post.url
+ post=@post
)
}}
>
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs
index b5a561a320d..31cd9939761 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs
@@ -1216,6 +1216,7 @@ export default class PostEventBuilder extends Component {
"discourse_post_event.builder_modal.custom_fields.description"
}}
@format="full"
+ class="form-kit__container-custom-fields"
>
<form.Object @name="customFields" as |customFields|>
{{#each this.allowedCustomFields as |allowedCustomField|}}
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/initializers/discourse-post-event-decorator.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/initializers/discourse-post-event-decorator.gjs
index 7a7db1d6ab5..0d3a8a54409 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/initializers/discourse-post-event-decorator.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/initializers/discourse-post-event-decorator.gjs
@@ -62,7 +62,9 @@ function initializeDiscoursePostEventDecorator(api) {
helper.renderGlimmer(
wrapper,
- <template><DiscoursePostEvent @event={{event}} /></template>
+ <template>
+ <DiscoursePostEvent @event={{event}} @post={{post}} />
+ </template>
);
}
},
diff --git a/plugins/discourse-calendar/test/javascripts/integration/components/discourse-post-event-test.gjs b/plugins/discourse-calendar/test/javascripts/integration/components/discourse-post-event-test.gjs
index 03a58f23c89..eb1ef5ee95f 100644
--- a/plugins/discourse-calendar/test/javascripts/integration/components/discourse-post-event-test.gjs
+++ b/plugins/discourse-calendar/test/javascripts/integration/components/discourse-post-event-test.gjs
@@ -1,5 +1,5 @@
import { getOwner } from "@ember/owner";
-import { render, waitFor } from "@ember/test-helpers";
+import { click, render, waitFor } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import DiscoursePostEvent from "../../discourse/components/discourse-post-event";
@@ -68,6 +68,53 @@ module("Integration | Component | DiscoursePostEvent", function (hooks) {
);
});
+ test("wires up the event image lightbox inside a topic", async function (assert) {
+ stubApi.call(
+ this,
+ buildEvent({
+ image_upload: { url: "/uploads/default/original/1X/event.png" },
+ })
+ );
+
+ const event = { id: 1, startsAt: "2026-06-04T14:00:00Z" };
+ await render(<template><DiscoursePostEvent @event={{event}} /></template>);
+ await waitFor(".event-image a.lightbox");
+ await click(".event-image a.lightbox");
+ await waitFor(".pswp--open");
+
+ assert.dom(".pswp--open").exists("opens the PhotoSwipe lightbox");
+
+ await click(".pswp__button--close");
+ });
+
+ test("links the event image to the post when linkToPost is set", async function (assert) {
+ stubApi.call(
+ this,
+ buildEvent({
+ image_upload: { url: "/uploads/default/original/1X/event.png" },
+ })
+ );
+
+ const event = { id: 1, startsAt: "2026-06-04T14:00:00Z" };
+ await render(
+ <template>
+ <DiscoursePostEvent @event={{event}} @linkToPost={{true}} />
+ </template>
+ );
+ await waitFor(".event-image");
+
+ assert
+ .dom(".event-image a.lightbox")
+ .doesNotExist("does not wire up a lightbox in calendar contexts");
+ assert
+ .dom(".event-image a")
+ .hasAttribute(
+ "href",
+ "/t/foo/1",
+ "links the image to the event topic instead"
+ );
+ });
+
test("derives the weekday from the date for all-day events, ignoring the timezone offset", async function (assert) {
// Midnight UTC in a negative-offset timezone rolls back to the previous
// day; an all-day event's weekday must come from the date, not the offset.