Skip to content

Commit

Permalink
✨ Order events on front page
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshHeng committed Jun 9, 2024
1 parent ae652e7 commit b16ee02
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/app/(home)/components/whats-on.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default async function WhatsOn() {
.
</p>

<p className="font-bold mb-1">Coming up Next:</p>
<div className="mx-4 mb-4 flex justify-center flex-wrap gap-4">
{events.map((event) => (
<EventCard
Expand Down
8 changes: 7 additions & 1 deletion src/app/events/components/event-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function EventCard({
spacingClasses?: string;
pastEvent?: boolean;
}) {
const currentTime = new Date().getTime();
return (
<a
href={`/events/${event.slug}`}
Expand All @@ -27,7 +28,12 @@ export default function EventCard({
>
<div className="text-xs">
{event.schedule_eventinstance.map((instance) => (
<p key={instance.id}>
<p
key={instance.id}
className={
instance.end.getTime() < currentTime ? 'line-through' : ''
}
>
<time dateTime={instance.start.toISOString()}>
{formatShowDateTime(instance.start)}
</time>{' '}
Expand Down
2 changes: 1 addition & 1 deletion src/app/schedule/components/schedule-event-instance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function ScheduleEventInstance({
return (
<a
href={`/events/${eventInstance.schedule_event.slug}`}
className={`block w-52 ${eventPage ? 'hover:scale-105' : 'mr-3'} ${eventInstance.start.getTime() - new Date().getTime() > 0 ? '' : 'opacity-50 line-through'}`}
className={`block w-52 ${eventPage ? 'hover:scale-105' : 'mr-3'} ${eventInstance.end.getTime() - new Date().getTime() > 0 ? '' : 'opacity-50 line-through'}`}
>
<article
className={`group p-2 ${getEventColourClasses(eventInstance.schedule_event)} drop-shadow-md h-full relative`}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function getEvents(
schedule_eventinstance: {
some: {
published: true,
start: pastEvents
end: pastEvents
? pastEvents === 1
? { gte: new Date() }
: { lte: new Date() }
Expand Down Expand Up @@ -117,10 +117,10 @@ export async function getEvents(
.map((val) => ({
val,
earliest:
(pastEvents !== 1
(pastEvents !== 1 && false
? val.schedule_eventinstance[0]?.start?.getTime()
: val.schedule_eventinstance
.filter((instance) => instance.end.getTime() < currentTime)[0]
.filter((instance) => instance.end.getTime() >= currentTime)[0]
?.start?.getTime()) || 0,
}))
.sort((a, b) => a.earliest - b.earliest)
Expand Down

0 comments on commit b16ee02

Please sign in to comment.