Skip to content

Commit

Permalink
Update events page (#421)
Browse files Browse the repository at this point in the history
* Updated date formating to allow string based dates on events page

* Update event-data.js

* Update event-data.js

* Add files via upload

* Delete src/images/events/hackathon.png

* Add files via upload

---------

Co-authored-by: Gábor Tamás <[email protected]>
  • Loading branch information
alex-beckett and gabros20 authored Nov 22, 2024
1 parent 4827afe commit 8418442
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/components/modules/event-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@ const EventList = ({ eventsNumber, hasEventType, isNotFeatured, pastEvents }) =>
const getFilteredEvents = (count) => {
let filteredEvents = eventData;
const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0); // Set to start of day for accurate comparison
currentDate.setHours(0, 0, 0, 0);

// Filter events based on hasEventType if provided
if (hasEventType) {
filteredEvents = filteredEvents.filter((event) => event.eventType === hasEventType);
}

// Exclude featured events if isNotFeatured is true
if (isNotFeatured) {
filteredEvents = filteredEvents.filter((event) => !event.featured);
}

// Filter for past events or future/current events based on pastEvents prop
if (pastEvents) {
filteredEvents = filteredEvents.filter((event) => new Date(event.endDate || event.startDate) < currentDate);
filteredEvents = filteredEvents.filter((event) => {
if (!event.startDate.includes("-")) return false;
return new Date(event.endDate || event.startDate) < currentDate;
});
} else {
filteredEvents = filteredEvents.filter((event) => new Date(event.startDate) >= currentDate);
filteredEvents = filteredEvents.filter((event) => {
if (!event.startDate.includes("-")) return true;
return new Date(event.startDate) >= currentDate;
});
}

// Sort events by date
const sortedEvents = filteredEvents.sort((a, b) => {
return pastEvents
? new Date(b.startDate) - new Date(a.startDate) // Descending order for past events
: new Date(a.startDate) - new Date(b.startDate); // Ascending order for future events
if (!a.startDate.includes("-")) return 1;
if (!b.startDate.includes("-")) return -1;

return pastEvents ? new Date(b.startDate) - new Date(a.startDate) : new Date(a.startDate) - new Date(b.startDate);
});

// Return the specified number of events, or all if count is not provided
return count ? sortedEvents.slice(0, count) : sortedEvents;
};

Expand Down
15 changes: 14 additions & 1 deletion src/datas/events/event-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const eventData = [
location: "Bangkok",
category: ["", ""],
url: "https://lu.ma/2qzkjf9d",
featured: true,
featured: false,
},
{
id: 4,
Expand Down Expand Up @@ -194,6 +194,19 @@ export const eventData = [
url: "https://lu.ma/rvqi5xev",
featured: false,
},
{
id: 19,
eventType: "celestia", // celestia, community
image: "events/hackathon.png", // use 1200x800px image for cover image (3:2 ratio)
title: "Celestia hackathon",
description: "",
startDate: "Comming soon!",
endDate: "",
location: "Online",
category: ["", ""],
url: "#",
featured: true,
},
];

export const submitButton = {
Expand Down
Binary file added src/images/events/hackathon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/utils/date-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export function formatDateRange(startDate, endDate) {
// Handle text-based dates (e.g., "Upcoming", "TBD")
if (!startDate.includes("-")) {
return startDate;
}

const start = new Date(startDate);
const end = endDate ? new Date(endDate) : null;

Expand Down

0 comments on commit 8418442

Please sign in to comment.