Skip to content

Commit

Permalink
Fix Minified React Error
Browse files Browse the repository at this point in the history
  • Loading branch information
sirAvent committed Nov 2, 2023
1 parent ceaaf42 commit 157608e
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/components/events/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FaExternalLinkAlt } from "react-icons/fa";
import EventsData from "../../../assets/events.json";
import { useEffect, useState } from "react";

function getFormattedDate(date) {
const dateObject = new Date(date + "T00:00:00").toLocaleDateString("en-US", {
Expand All @@ -12,25 +13,34 @@ function getFormattedDate(date) {
return dateObject;
}

function getSortedSchedule(schedule) {
const sortedSchedule = {};
export default function EventsSection() {
const [sortedSchedule, setSortedSchedule] = useState([]);

schedule.forEach((event) => {
const date = event.date;
if (!sortedSchedule[date]) {
sortedSchedule[date] = [];
}
sortedSchedule[date].push(event);
});
useEffect(() => {
const schedule = EventsData.schedule;
const sortedSchedule = {};

const sortedEvents = Object.values(sortedSchedule);
schedule.forEach((event) => {
const date = event.date;
if (!sortedSchedule[date]) {
sortedSchedule[date] = [];
}
sortedSchedule[date].push(event);
});

return sortedEvents;
}
// Sort the events by time here
const sortedEvents = Object.values(sortedSchedule).map((date) =>
date.sort((a, b) => {
const timeA =
parseInt(a.time, 10) + (a.time.includes("PM") ? 12 : 0);
const timeB =
parseInt(b.time, 10) + (b.time.includes("PM") ? 12 : 0);
return timeA - timeB;
})
);

export default function EventsSection() {
const schedule = EventsData.schedule;
const sortedSchedule = getSortedSchedule(schedule);
setSortedSchedule(sortedEvents);
}, []);

return (
<>
Expand Down

0 comments on commit 157608e

Please sign in to comment.