Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Adds ability to see multiday events in sidebar #609

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions assets/javascripts/discourse/components/upcoming-events-list.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,20 @@

groupByMonthAndDay(data) {
return data.reduce((result, item) => {
const date = new Date(item.starts_at);
const startDate = moment(item.starts_at);
const endDate = moment(item.ends_at);
const year = date.getFullYear();

Check failure on line 123 in assets/javascripts/discourse/components/upcoming-events-list.gjs

View workflow job for this annotation

GitHub Actions / ci / linting

'date' is not defined
const month = date.getMonth() + 1;

Check failure on line 124 in assets/javascripts/discourse/components/upcoming-events-list.gjs

View workflow job for this annotation

GitHub Actions / ci / linting

'date' is not defined
const day = date.getDate();

Check failure on line 125 in assets/javascripts/discourse/components/upcoming-events-list.gjs

View workflow job for this annotation

GitHub Actions / ci / linting

'date' is not defined

const monthKey = `${year}-${month}`;

if (startDate.isSameOrBefore(endDate, "day")) {
result[monthKey][day].push(item);

// Move to the next day
startDate.add(1, "day");
}

result[monthKey] = result[monthKey] ?? {};
result[monthKey][day] = result[monthKey][day] ?? [];

Expand Down Expand Up @@ -174,6 +181,7 @@
<div class="upcoming-events-list__day-section">
<div class="upcoming-events-list__formatted-day">
{{this.formatDate month day}}
{{log events}}

Check failure on line 184 in assets/javascripts/discourse/components/upcoming-events-list.gjs

View workflow job for this annotation

GitHub Actions / ci / linting

Unexpected {{log}} usage.
</div>

{{#each events as |event|}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,35 @@
exists(".upcoming-events-list__view-all"),
"it displays the view-all link"
);

test("with multi-day events, standard formats", async function (assert) {

Check failure on line 144 in test/javascripts/integration/components/upcoming-events-list-test.gjs

View workflow job for this annotation

GitHub Actions / ci / linting

Using QUnit.test inside of another QUnit.test is not allowed

Check failure on line 144 in test/javascripts/integration/components/upcoming-events-list-test.gjs

View workflow job for this annotation

GitHub Actions / ci / linting

'assert' is already declared in the upper scope on line 79 column 57
pretender.get(
"/discourse-post-event/events",
multiDayEventResponseHandler
);

await render(<template><UpcomingEventsList /></template>);

this.appEvents.trigger("page:changed", { url: "/" });

await waitFor(".loading-container .spinner", { count: 0 });

assert.deepEqual(
[...queryAll(".upcoming-events-list__event-name")].map(
(el) => el.innerText
),
["Awesome Event", "Another Awesome Event"],
"it displays the multiday event on all scheduled dates"
);

assert.deepEqual(
[...queryAll(".upcoming-events-list__event-name")].map(
(el) => el.innerText
),
["Awesome Event", "Another Awesome Event"],
"it displays the multiday event that has two different months"
);
});
});

test("with events, view-all navigation", async function (assert) {
Expand Down Expand Up @@ -394,3 +423,37 @@

return response({ events });
}

function multiDayEventResponseHandler({ queryParams }) {
let events = [
{
id: 67503,
starts_at: tomorrowAllDay,
ends_at: nextMonth,
timezone: "Asia/Calcutta",
post: {
id: 67501,
post_number: 1,
url: "/t/this-is-an-event/18451/1",
topic: {
id: 18449,
title: "This is a multiday event",
},
},
name: "Awesome MultiDay Event",
category_id: 1,
},
];

if (queryParams.limit) {
events.splice(queryParams.limit);
}

if (queryParams.before) {
events = events.filter((event) => {
return moment(event.starts_at).isBefore(queryParams.before);
});
}

return response({ events });
}
Loading