From e8f6776aa71080d66472ee0deb2a0046ab52118f Mon Sep 17 00:00:00 2001 From: chark1es Date: Mon, 17 Feb 2025 02:44:57 -0800 Subject: [PATCH] add hidden text codes --- src/components/dashboard/EventsSection.astro | 154 ++++++++----------- 1 file changed, 65 insertions(+), 89 deletions(-) diff --git a/src/components/dashboard/EventsSection.astro b/src/components/dashboard/EventsSection.astro index 49bb506..4f9d274 100644 --- a/src/components/dashboard/EventsSection.astro +++ b/src/components/dashboard/EventsSection.astro @@ -23,7 +23,7 @@ import FilePreview from "./Officer_EventManagement/FilePreview";
@@ -103,6 +103,21 @@ import FilePreview from "./Officer_EventManagement/FilePreview";
+ +
+
+

Ongoing Events

+
+ +
+
+
+
{ @@ -607,6 +630,7 @@ import FilePreview from "./Officer_EventManagement/FilePreview"; for (let i = 0; i < 3; i++) { upcomingEventsContainer.appendChild(createSkeletonCard()); + ongoingEventsContainer.appendChild(createSkeletonCard()); pastEventsContainer.appendChild(createSkeletonCard()); } @@ -619,11 +643,12 @@ import FilePreview from "./Officer_EventManagement/FilePreview"; // Clear skeletons upcomingEventsContainer.innerHTML = ""; + ongoingEventsContainer.innerHTML = ""; pastEventsContainer.innerHTML = ""; - // Split events into upcoming and past based on start and end dates + // Split events into upcoming, ongoing, and past based on start and end dates const now = new Date(); - const { upcoming, past } = events.reduce( + const { upcoming, ongoing, past } = events.reduce( (acc, event) => { // Convert UTC dates to local time const startDate = new Date(event.start_date); @@ -659,12 +684,16 @@ import FilePreview from "./Officer_EventManagement/FilePreview"; // If end date is in past, it's past acc.past.push(event); } else { - // If start date is past but end date is future, it's in progress (show in upcoming) - acc.upcoming.push(event); + // If start date is past but end date is future, it's ongoing + acc.ongoing.push(event); } return acc; }, - { upcoming: [] as Event[], past: [] as Event[] } + { + upcoming: [] as Event[], + ongoing: [] as Event[], + past: [] as Event[], + } ); // Sort upcoming events by start date (closest first) @@ -674,6 +703,13 @@ import FilePreview from "./Officer_EventManagement/FilePreview"; new Date(b.start_date).getTime() ); + // Sort ongoing events by end date (ending soonest first) + ongoing.sort( + (a, b) => + new Date(a.end_date).getTime() - + new Date(b.end_date).getTime() + ); + // Sort past events by end date (most recent first) past.sort( (a, b) => @@ -681,86 +717,7 @@ import FilePreview from "./Officer_EventManagement/FilePreview"; new Date(a.end_date).getTime() ); - upcoming.forEach((event) => { - const startDate = new Date(event.start_date); - const endDate = new Date(event.end_date); - - const card = document.createElement("div"); - card.className = - "card bg-base-200 shadow-lg hover:shadow-xl transition-all duration-300 relative overflow-hidden"; - card.innerHTML = ` -
-
-
-
-

${event.event_name}

-
-
${event.points_to_reward} pts
-
-
-
-
- ${startDate.toLocaleDateString( - "en-US", - { - weekday: "short", - month: "short", - day: "numeric", - } - )} -
-
- ${startDate.toLocaleTimeString( - "en-US", - { - hour: "numeric", - minute: "2-digit", - } - )} -
-
-
- -
- ${event.description || "No description available"} -
- -
-
- - ${event.location} -
- ${(() => { - const endDate = Get.isUTCDateString( - event.end_date - ) - ? new Date(event.end_date) - : new Date(); - const now = new Date(); - return endDate < now && - event.files && - event.files.length > 0 - ? ` - - ` - : ""; - })()} -
-
-
- `; - upcomingEventsContainer.appendChild(card); - }); - - past.forEach((event) => { + const renderEventCard = (event: Event, container: HTMLElement) => { const startDate = new Date(event.start_date); const endDate = new Date(event.end_date); @@ -832,8 +789,27 @@ import FilePreview from "./Officer_EventManagement/FilePreview";
`; - pastEventsContainer.appendChild(card); - }); + container.appendChild(card); + }; + + // Render all event types + upcoming.forEach((event) => + renderEventCard(event, upcomingEventsContainer) + ); + ongoing.forEach((event) => + renderEventCard(event, ongoingEventsContainer) + ); + past.forEach((event) => + renderEventCard(event, pastEventsContainer) + ); + + // Hide sections if they have no events + if (upcoming.length === 0) + upcomingEventsContainer.parentElement?.classList.add("hidden"); + if (ongoing.length === 0) + ongoingEventsContainer.parentElement?.classList.add("hidden"); + if (past.length === 0) + pastEventsContainer.parentElement?.classList.add("hidden"); } catch (error) { console.error("Failed to load events:", error); // You might want to show an error message to the user here