Skip to content

Commit

Permalink
added sorting based on event end time (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
NK-Works authored Nov 10, 2024
1 parent 25e3d92 commit d5bc4bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion frontend/src/appComponents/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const EventCard: React.FC<EventCardProps> = ({ name, description, time }) => {
</div>
<button onClick={()=>{
window.location.href = "https://forms.gle/u9s7BXa2onvAoVkr9";
}} className="px-4 py-2 text-sm font-bold text-white transition duration-300 bg-black rounded-md hover:bg-gray-800">
}} className="px-5 py-2 text-sm font-bold text-white transition duration-300 bg-black rounded-md hover:bg-gray-800 ml-10">
Register
</button>
</div>
Expand Down
39 changes: 20 additions & 19 deletions frontend/src/appComponents/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,34 @@ const Events = () => {
];

// Get the day, month, year, hours and minutes
let day = start.getDate();
let month = monthNames[start.getMonth()];
let year = start.getFullYear();
let startHours = start.getHours();
let startMinutes: string | number = start.getMinutes();
let day = end.getDate();
let month = monthNames[end.getMonth()];
let year = end.getFullYear();
// let startHours = end.getHours();
// let startMinutes: string | number = end.getMinutes();
let endHours = end.getHours();
let endMinutes: string | number = end.getMinutes();

// Convert hours from 24-hour format to 12-hour format
let startPeriod = startHours >= 12 ? "PM" : "AM";
startHours = startHours % 12;
startHours = startHours ? startHours : 12; // the hour '0' should be '12'
// // Convert hours from 24-hour format to 12-hour format
// let startPeriod = startHours >= 12 ? "PM" : "AM";
// startHours = startHours % 12;
// startHours = startHours ? startHours : 12; // the hour '0' should be '12'
let endPeriod = endHours >= 12 ? "PM" : "AM";
endHours = endHours % 12;
endHours = endHours ? endHours : 12; // the hour '0' should be '12'

// Pad minutes with a zero if needed
startMinutes = startMinutes < 10 ? "0" + startMinutes : startMinutes;
// // Pad minutes with a zero if needed
// startMinutes = startMinutes < 10 ? "0" + startMinutes : startMinutes;
endMinutes = endMinutes < 10 ? "0" + endMinutes : endMinutes;

// Return the formatted date and time range
return (
return ("ET: " +
day +
"/" +
month +
"/" +
year +
" " +
startHours +
":" +
startMinutes +
" " +
startPeriod +
" to " +
endHours +
":" +
endMinutes +
Expand All @@ -74,7 +68,14 @@ const Events = () => {
useEffect(() => {
const getAllEvents = async () => {
const response = await axios.get("/api/events/getAllEventData");
setEvents(response.data);
const currentDate = new Date();
// Filter out events that have already ended
const upcomingEvents = response.data.filter((event: any) => {
const eventEndDate = new Date(event.EndDateTime);
return eventEndDate >= currentDate;
});

setEvents(upcomingEvents);
};
getAllEvents();
}, []);
Expand Down

0 comments on commit d5bc4bf

Please sign in to comment.