From f67a3710daa2fd3033465da408bd31f619e6e0cc Mon Sep 17 00:00:00 2001 From: prasanth-ideas2it Date: Thu, 28 Nov 2024 18:12:52 +0530 Subject: [PATCH 1/2] fix: IRL events sort --- components/page/irl/events/irl-all-events.tsx | 46 +++++++++---------- .../page/irl/events/irl-past-events.tsx | 1 - .../page/irl/events/irl-upcoming-events.tsx | 46 +++++++++---------- services/irl.service.ts | 12 ++--- 4 files changed, 52 insertions(+), 53 deletions(-) diff --git a/components/page/irl/events/irl-all-events.tsx b/components/page/irl/events/irl-all-events.tsx index 69bc06ff..d143f1b5 100644 --- a/components/page/irl/events/irl-all-events.tsx +++ b/components/page/irl/events/irl-all-events.tsx @@ -23,7 +23,7 @@ interface EventDetailsProps { const IrlAllEvents = ({ eventDetails, isLoggedIn, isUpcoming, searchParams, handleDataNotFound }: EventDetailsProps) => { - let eventsToShow = getEventsToShow() || []; + let eventsToShow = eventDetails.events || []; const [isExpanded, setExpanded] = useState(false); const [itemsToShow, setItemsToShow] = useState(4); const dialogRef = useRef(null); @@ -31,33 +31,33 @@ const IrlAllEvents = ({ eventDetails, isLoggedIn, isUpcoming, searchParams, hand const analytics = useIrlAnalytics(); const router = useRouter(); - function getEventsToShow() { - if (eventDetails) { - // Determine events to show based on upcoming or past - const events = eventDetails.events; + // function getEventsToShow() { + // if (eventDetails) { + // // Determine events to show based on upcoming or past + // const events = eventDetails.events; - if (events && events.length > 0) { - // Sort events based on startDate first, then by duration (endDate - startDate) - const sortedEvents = events.sort((a: any, b: any) => { - // First, compare by start date (earlier start first) - const startDateComparison = new Date(a.startDate).getTime() - new Date(b.startDate).getTime(); + // if (events && events.length > 0) { + // // Sort events based on startDate first, then by duration (endDate - startDate) + // const sortedEvents = events.sort((a: any, b: any) => { + // // First, compare by start date (earlier start first) + // const startDateComparison = new Date(a.startDate).getTime() - new Date(b.startDate).getTime(); - if (startDateComparison !== 0) { - return startDateComparison; - } + // if (startDateComparison !== 0) { + // return startDateComparison; + // } - // If start dates are equal, compare by duration (longer duration first) - const durationA = new Date(a.endDate).getTime() - new Date(a.startDate).getTime(); - const durationB = new Date(b.endDate).getTime() - new Date(b.startDate).getTime(); + // // If start dates are equal, compare by duration (longer duration first) + // const durationA = new Date(a.endDate).getTime() - new Date(a.startDate).getTime(); + // const durationB = new Date(b.endDate).getTime() - new Date(b.startDate).getTime(); - return durationB - durationA; - }); + // return durationB - durationA; + // }); - // Set eventsToShow based on the sorted events - return sortedEvents; - } - } - } + // // Set eventsToShow based on the sorted events + // return sortedEvents; + // } + // } + // } const toggleDescription = () => { setItemsToShow(isExpanded ? 4 : itemsToShow + 4); diff --git a/components/page/irl/events/irl-past-events.tsx b/components/page/irl/events/irl-past-events.tsx index 339f0826..ea90741d 100644 --- a/components/page/irl/events/irl-past-events.tsx +++ b/components/page/irl/events/irl-past-events.tsx @@ -43,7 +43,6 @@ const IrlPastEvents = ({ eventDetails, isLoggedIn, isUpcoming, searchParams, han const [searchText, setSearchText] = useState(''); - // Sort pastEvents in descending order by end date if it's not upcoming const eventsToShow = events; // Determine the selected event based on searchParams diff --git a/components/page/irl/events/irl-upcoming-events.tsx b/components/page/irl/events/irl-upcoming-events.tsx index 975f043c..752ef62b 100644 --- a/components/page/irl/events/irl-upcoming-events.tsx +++ b/components/page/irl/events/irl-upcoming-events.tsx @@ -22,7 +22,7 @@ interface EventDetailsProps { const IrlUpcomingEvents = ({ eventDetails, isLoggedIn, isUpcoming, searchParams, handleDataNotFound }: EventDetailsProps) => { const eventType = isUpcoming ? 'Upcoming Events' : 'Past Events'; - let eventsToShow = getEventsToShow() || []; + let eventsToShow = eventDetails.upcomingEvents || []; const [isExpanded, setExpanded] = useState(false); const [itemsToShow, setItemsToShow] = useState(4); const dialogRef = useRef(null); @@ -30,33 +30,33 @@ const IrlUpcomingEvents = ({ eventDetails, isLoggedIn, isUpcoming, searchParams, const analytics = useIrlAnalytics(); const router = useRouter(); - function getEventsToShow() { - if (eventDetails) { - // Determine events to show based on upcoming or past - const events = isUpcoming ? eventDetails.upcomingEvents : []; + // function getEventsToShow() { + // if (eventDetails) { + // // Determine events to show based on upcoming or past + // const events = isUpcoming ? eventDetails.upcomingEvents : []; - if (events && events.length > 0) { - // Sort events based on startDate first, then by duration (endDate - startDate) - const sortedEvents = events.sort((a: any, b: any) => { - // First, compare by start date (earlier start first) - const startDateComparison = new Date(a.startDate).getTime() - new Date(b.startDate).getTime(); + // if (events && events.length > 0) { + // // Sort events based on startDate first, then by duration (endDate - startDate) + // const sortedEvents = events.sort((a: any, b: any) => { + // // First, compare by start date (earlier start first) + // const startDateComparison = new Date(a.startDate).getTime() - new Date(b.startDate).getTime(); - if (startDateComparison !== 0) { - return startDateComparison; - } + // if (startDateComparison !== 0) { + // return startDateComparison; + // } - // If start dates are equal, compare by duration (longer duration first) - const durationA = new Date(a.endDate).getTime() - new Date(a.startDate).getTime(); - const durationB = new Date(b.endDate).getTime() - new Date(b.startDate).getTime(); + // // If start dates are equal, compare by duration (longer duration first) + // const durationA = new Date(a.endDate).getTime() - new Date(a.startDate).getTime(); + // const durationB = new Date(b.endDate).getTime() - new Date(b.startDate).getTime(); - return durationB - durationA; - }); + // return durationB - durationA; + // }); - // Set eventsToShow based on the sorted events - return sortedEvents; - } - } - } + // // Set eventsToShow based on the sorted events + // return sortedEvents; + // } + // } + // } const toggleDescription = () => { setItemsToShow(isExpanded ? 4 : itemsToShow + 4); diff --git a/services/irl.service.ts b/services/irl.service.ts index 53fa580f..25850038 100644 --- a/services/irl.service.ts +++ b/services/irl.service.ts @@ -15,13 +15,13 @@ export const getAllLocations = async () => { } const result = await response.json(); - result.sort((a: { priority: number }, b: { priority: number }) => a.priority - b.priority); + // result.sort((a: { priority: number }, b: { priority: number }) => a.priority - b.priority); - result.forEach((item: { pastEvents: any[] }) => { - if (Array.isArray(item.pastEvents)) { - item.pastEvents = sortPastEvents(item.pastEvents); - } - }); + // result.forEach((item: { pastEvents: any[] }) => { + // if (Array.isArray(item.pastEvents)) { + // item.pastEvents = sortPastEvents(item.pastEvents); + // } + // }); const filteredResult = result.filter( (item: { pastEvents: IPastEvents[]; upcomingEvents: IUpcomingEvents[]; }) => From c317a75215f5d5fc4e056d82901089d54e38469f Mon Sep 17 00:00:00 2001 From: prasanth-ideas2it Date: Thu, 28 Nov 2024 18:18:18 +0530 Subject: [PATCH 2/2] fix: sort code removal --- components/page/irl/events/irl-all-events.tsx | 28 ------------------- .../page/irl/events/irl-upcoming-events.tsx | 28 ------------------- services/irl.service.ts | 7 ----- 3 files changed, 63 deletions(-) diff --git a/components/page/irl/events/irl-all-events.tsx b/components/page/irl/events/irl-all-events.tsx index d143f1b5..ebf16884 100644 --- a/components/page/irl/events/irl-all-events.tsx +++ b/components/page/irl/events/irl-all-events.tsx @@ -31,34 +31,6 @@ const IrlAllEvents = ({ eventDetails, isLoggedIn, isUpcoming, searchParams, hand const analytics = useIrlAnalytics(); const router = useRouter(); - // function getEventsToShow() { - // if (eventDetails) { - // // Determine events to show based on upcoming or past - // const events = eventDetails.events; - - // if (events && events.length > 0) { - // // Sort events based on startDate first, then by duration (endDate - startDate) - // const sortedEvents = events.sort((a: any, b: any) => { - // // First, compare by start date (earlier start first) - // const startDateComparison = new Date(a.startDate).getTime() - new Date(b.startDate).getTime(); - - // if (startDateComparison !== 0) { - // return startDateComparison; - // } - - // // If start dates are equal, compare by duration (longer duration first) - // const durationA = new Date(a.endDate).getTime() - new Date(a.startDate).getTime(); - // const durationB = new Date(b.endDate).getTime() - new Date(b.startDate).getTime(); - - // return durationB - durationA; - // }); - - // // Set eventsToShow based on the sorted events - // return sortedEvents; - // } - // } - // } - const toggleDescription = () => { setItemsToShow(isExpanded ? 4 : itemsToShow + 4); if (itemsToShow >= eventsToShow?.length - 4) { diff --git a/components/page/irl/events/irl-upcoming-events.tsx b/components/page/irl/events/irl-upcoming-events.tsx index 752ef62b..81d6c39e 100644 --- a/components/page/irl/events/irl-upcoming-events.tsx +++ b/components/page/irl/events/irl-upcoming-events.tsx @@ -30,34 +30,6 @@ const IrlUpcomingEvents = ({ eventDetails, isLoggedIn, isUpcoming, searchParams, const analytics = useIrlAnalytics(); const router = useRouter(); - // function getEventsToShow() { - // if (eventDetails) { - // // Determine events to show based on upcoming or past - // const events = isUpcoming ? eventDetails.upcomingEvents : []; - - // if (events && events.length > 0) { - // // Sort events based on startDate first, then by duration (endDate - startDate) - // const sortedEvents = events.sort((a: any, b: any) => { - // // First, compare by start date (earlier start first) - // const startDateComparison = new Date(a.startDate).getTime() - new Date(b.startDate).getTime(); - - // if (startDateComparison !== 0) { - // return startDateComparison; - // } - - // // If start dates are equal, compare by duration (longer duration first) - // const durationA = new Date(a.endDate).getTime() - new Date(a.startDate).getTime(); - // const durationB = new Date(b.endDate).getTime() - new Date(b.startDate).getTime(); - - // return durationB - durationA; - // }); - - // // Set eventsToShow based on the sorted events - // return sortedEvents; - // } - // } - // } - const toggleDescription = () => { setItemsToShow(isExpanded ? 4 : itemsToShow + 4); if (itemsToShow >= eventsToShow?.length - 4) { diff --git a/services/irl.service.ts b/services/irl.service.ts index 25850038..c8b03c90 100644 --- a/services/irl.service.ts +++ b/services/irl.service.ts @@ -15,13 +15,6 @@ export const getAllLocations = async () => { } const result = await response.json(); - // result.sort((a: { priority: number }, b: { priority: number }) => a.priority - b.priority); - - // result.forEach((item: { pastEvents: any[] }) => { - // if (Array.isArray(item.pastEvents)) { - // item.pastEvents = sortPastEvents(item.pastEvents); - // } - // }); const filteredResult = result.filter( (item: { pastEvents: IPastEvents[]; upcomingEvents: IUpcomingEvents[]; }) =>