diff --git a/src/components/page-sections/events.tsx b/src/components/page-sections/events.tsx index 8512768..ddc5ef9 100644 --- a/src/components/page-sections/events.tsx +++ b/src/components/page-sections/events.tsx @@ -1,4 +1,4 @@ -import { getAllEvents } from "@/lib/sanity" +import { getUpcomingEvents } from "@/lib/sanity" import { getLocale, getTranslations } from "next-intl/server" import Image from "next/image" @@ -25,14 +25,7 @@ const Events = async () => { const tCommon = await getTranslations("common") const locale = await getLocale() - const data: Event[] = await getAllEvents() - - const currentDate = new Date() - const filteredEvents = data - .filter((event: Event) => { - return currentDate <= new Date(event.date) - }) - .slice(0, 2) + const events: Event[] = await getUpcomingEvents(2) const formatDate = (dateString: string) => { const date = new Date(dateString) @@ -105,7 +98,7 @@ const Events = async () => {

{t("title")}

-
{mapEvents(filteredEvents)}
+
{mapEvents(events)}
[type, value]) + ) + const now = `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}` + const query = ` - *[_type == "event"] | order(date asc) { + *[_type == "event" && date >= $now] | order(date asc)[0...$limit] { _id, title, location, @@ -85,7 +103,7 @@ export async function getAllEvents() { return sanityClient.fetch( query, - {}, + { now, limit }, { cache: "force-cache", next: {