diff --git a/src/app/pages/Events/Events.js b/src/app/pages/Events/Events.js index 43b590f0..41640efd 100644 --- a/src/app/pages/Events/Events.js +++ b/src/app/pages/Events/Events.js @@ -1,4 +1,4 @@ -import { useState, useEffect } from "react"; +import { useState, useEffect, useCallback } from "react"; import { Helmet } from "react-helmet"; import { Link } from "react-router-dom"; @@ -38,8 +38,6 @@ const joinEvents = (a, b) => { a = a.upcoming && a.past ? a : { upcoming: [], past: [] }; b = b.upcoming && b.past ? b : { upcoming: [], past: [] }; - console.log("ab", a, b); - const combinedUpcoming = [...a.upcoming, ...b.upcoming]; const combinedPast = [...a.past, ...b.past]; @@ -59,38 +57,37 @@ const joinEvents = (a, b) => { }; }; +const legacyEvents = parseEvents(EVENT_DATA); // events from manual JSON file + const Events = () => { - const legacyEvents = parseEvents(EVENT_DATA); // events from manual JSON file - const [sanityEvents, setSanityEvents] = useState([]); const [events, setEvents] = useState(); - const fetchEvents = async () => { - return client - .fetch(`*[_type == "event"] | order(time desc)`, {}) - .then((result) => - result.map((item) => ({ - title: item.title, - time: item.time, - duration: item.duration, - type: item.type, - desc: item.desc, - place: item.place, - links: item.links - ? item.links.map((linkItem) => ({ - label: linkItem.label, - link: linkItem.link, - })) - : [], - })), - ); - }; + const fetchEvents = useCallback(async () => { + const result = await client.fetch( + `*[_type == "event"] | order(time desc)`, + {}, + ); + return result.map((item) => ({ + title: item.title, + time: item.time, + duration: item.duration, + type: item.type, + desc: item.desc, + place: item.place, + links: item.links + ? item.links.map((linkItem) => ({ + label: linkItem.label, + link: linkItem.link, + })) + : [], + })); + }, []); useEffect(async () => { try { const data = await fetchEvents(); const eventData = parseEvents(data); - setSanityEvents(eventData); const joinedEvents = joinEvents(eventData, legacyEvents); setEvents(joinedEvents); } catch (e) { @@ -158,36 +155,6 @@ const Events = () => { )} - {events != null && events.upcoming.length > 0 && ( - <> -
- - Next Upcoming Event - {events.upcoming.length > 1 ? "s" : ""} - -
-
-
- {events.upcoming.map((event, i) => { - return ( - - ); - })} -
-
- - )}