From ae652e7b9470500277ca266960764900126ace19 Mon Sep 17 00:00:00 2001
From: Josh Heng
Date: Sun, 9 Jun 2024 15:30:12 +0100
Subject: [PATCH 1/2] :sparkles: Try to order front page
---
src/app/(home)/components/whats-on.tsx | 2 +-
src/lib/events.ts | 15 +++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/app/(home)/components/whats-on.tsx b/src/app/(home)/components/whats-on.tsx
index fdc413c..5ff2399 100644
--- a/src/app/(home)/components/whats-on.tsx
+++ b/src/app/(home)/components/whats-on.tsx
@@ -3,7 +3,7 @@ import { getEvents } from '@/lib/events';
import EventCard from '@/app/events/components/event-card';
export default async function WhatsOn() {
- const events = (await getEvents(true, 1)).slice(0, 6);
+ const events = (await getEvents(false, 1)).slice(0, 6);
return (
diff --git a/src/lib/events.ts b/src/lib/events.ts
index a002797..d5e3714 100644
--- a/src/lib/events.ts
+++ b/src/lib/events.ts
@@ -102,6 +102,7 @@ export async function getEvents(
schedule_eventinstance: {
where: { published: true },
include: { schedule_venue: true },
+ orderBy: { start: 'asc' },
},
},
});
@@ -110,6 +111,20 @@ export async function getEvents(
.map((val) => ({ val, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map((val) => val.val);
+ } else {
+ const currentTime = new Date().getTime();
+ events = events
+ .map((val) => ({
+ val,
+ earliest:
+ (pastEvents !== 1
+ ? val.schedule_eventinstance[0]?.start?.getTime()
+ : val.schedule_eventinstance
+ .filter((instance) => instance.end.getTime() < currentTime)[0]
+ ?.start?.getTime()) || 0,
+ }))
+ .sort((a, b) => a.earliest - b.earliest)
+ .map((val) => val.val);
}
return events;
From b16ee02a2289dc9c08dcd00c0c5b5490f11a2cd5 Mon Sep 17 00:00:00 2001
From: Josh Heng
Date: Sun, 9 Jun 2024 21:15:36 +0100
Subject: [PATCH 2/2] :sparkles: Order events on front page
---
src/app/(home)/components/whats-on.tsx | 1 +
src/app/events/components/event-card.tsx | 8 +++++++-
src/app/schedule/components/schedule-event-instance.tsx | 2 +-
src/lib/events.ts | 6 +++---
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/app/(home)/components/whats-on.tsx b/src/app/(home)/components/whats-on.tsx
index 5ff2399..74118c4 100644
--- a/src/app/(home)/components/whats-on.tsx
+++ b/src/app/(home)/components/whats-on.tsx
@@ -26,6 +26,7 @@ export default async function WhatsOn() {
.
+ Coming up Next: