Skip to content

Commit

Permalink
Merge pull request #397 from memser-spaceport/develop
Browse files Browse the repository at this point in the history
fix: IRL events sort
  • Loading branch information
madan-ideas2it authored Nov 28, 2024
2 parents 52864d6 + c317a75 commit 7d83581
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 66 deletions.
30 changes: 1 addition & 29 deletions components/page/irl/events/irl-all-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,14 @@ 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<HTMLDivElement>(null);
const [resources, setResources] = useState([]);
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) {
Expand Down
1 change: 0 additions & 1 deletion components/page/irl/events/irl-past-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 1 addition & 29 deletions components/page/irl/events/irl-upcoming-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,14 @@ 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<HTMLDivElement>(null);
const [resources, setResources] = useState([]);
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) {
Expand Down
7 changes: 0 additions & 7 deletions services/irl.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]; }) =>
Expand Down

0 comments on commit 7d83581

Please sign in to comment.