Skip to content

Commit

Permalink
Address feedback, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
brrusselburg committed Oct 28, 2024
1 parent c5ee914 commit 3d3eccd
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions assets/javascripts/discourse/components/upcoming-events-list.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ export const DEFAULT_TIME_FORMAT = "LT";
const DEFAULT_UPCOMING_DAYS = 180;
const DEFAULT_COUNT = 8;

function addToResult(date, item, result) {
const year = date.year();
const month = date.month() + 1;
const day = date.date();
const monthKey = `${year}-${month}`;

result[monthKey] = result[monthKey] ?? {};
console.log("HERE?????");

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

View workflow job for this annotation

GitHub Actions / ci / linting

Unexpected console statement
result[monthKey][day] = result[monthKey][day] ?? [];
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!");

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

View workflow job for this annotation

GitHub Actions / ci / linting

Unexpected console statement
result[monthKey][day].push(item);
}

export default class UpcomingEventsList extends Component {
@service appEvents;
@service siteSettings;
Expand Down Expand Up @@ -110,38 +123,30 @@ export default class UpcomingEventsList extends Component {
return data.reduce((result, item) => {
const startDate = moment(item.starts_at);
const endDate = item.ends_at ? moment(item.ends_at) : null;
const today = moment();

if (endDate && !startDate.isSame(endDate)) {
while (startDate.isSameOrBefore(endDate, "day")) {
const year = startDate.year();
const month = startDate.month() + 1;
const day = startDate.date();
const monthKey = `${year}-${month}`;
const today = moment();
// NO END DATE --OR-- START DATE DAY === END DATE DAY
if (!endDate) {
console.log("SINGLE DAY");

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

View workflow job for this annotation

GitHub Actions / ci / linting

Unexpected console statement

// For current events, only push upcoming days
if (startDate.isAfter(today)) {
result[monthKey] = result[monthKey] || {};
result[monthKey][day] = result[monthKey][day] || [];
addToResult(startDate, item, result);
return result;
}

result[monthKey][day].push(item);
}
// START DATE === END DATE --OR-- START DATE << END DATE
while (startDate.isSameOrBefore(endDate, "day")) {
console.log("EXTENDED DAY");

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

View workflow job for this annotation

GitHub Actions / ci / linting

Unexpected console statement

// Move to the next day
startDate.add(1, "day");
// For current events, only push upcoming days
if (startDate.isAfter(today)) {
// the problem appears to be here! isAfter()
console.log("RIGHT HERE BEFORE THE FUNC");

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

View workflow job for this annotation

GitHub Actions / ci / linting

Unexpected console statement
addToResult(startDate, item, result);
}
} else {
const date = new Date(item.starts_at);
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();

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

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

result[monthKey][day].push(item);
console.log("MOVE TO NEXT DAY");

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

View workflow job for this annotation

GitHub Actions / ci / linting

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

return result;
Expand Down

0 comments on commit 3d3eccd

Please sign in to comment.