Skip to content

Commit

Permalink
Merge branch 'attempt-to-order-front-page'
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshHeng committed Jun 9, 2024
2 parents eec0dc7 + b16ee02 commit c33d5b7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app/(home)/components/whats-on.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<section className="mb-8">
Expand All @@ -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
17 changes: 16 additions & 1 deletion 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 All @@ -102,6 +102,7 @@ export async function getEvents(
schedule_eventinstance: {
where: { published: true },
include: { schedule_venue: true },
orderBy: { start: 'asc' },
},
},
});
Expand All @@ -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 && false
? 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;
Expand Down

0 comments on commit c33d5b7

Please sign in to comment.