Upcoming Events

You can find the upcoming events page in the pages/my-events folder and at http://localhost:3000/my-events/upcoming.

At the top of the file we can import our helper utilities again.

import { useState } from "react"; import { gql, useQuery } from "@apollo/client"; import { ConnectButton } from "@rainbow-me/rainbowkit"; import { useAccount } from "wagmi"; import EventCard from "../../components/EventCard";

For the upcoming events created by the user, we want to make sure we are only fetching future events where the eventOwner is equal to the wallet address of the user.

We can do this by combining these two conditions with the where keyword and the _gt modifier.

const MY_UPCOMING_EVENTS = gql` query Events($eventOwner: String, $currentTimestamp: String) { events( where: { eventOwner: $eventOwner, eventTimestamp_gt: $currentTimestamp } ) { id eventID name description eventTimestamp maxCapacity totalRSVPs imageURL } } `;

Next we can set up our query result and connect wallet button just as we have done on other pages and map our results to show event cards.

export default function MyUpcomingEvents() { const { data: account } = useAccount(); const eventOwner = account ? account.address.toLowerCase() : ""; const [currentTimestamp, setEventTimestamp] = useState( new Date().getTime().toString() ); const { loading, error, data } = useQuery(MY_UPCOMING_EVENTS, { variables: { eventOwner, currentTimestamp }, }); if (loading) return ( <Dashboard page="events" isUpcoming={true}> <p>Loading...</p> </Dashboard> ); if (error) return ( <Dashboard page="events" isUpcoming={true}> <p>`Error! ${error.message}`</p> </Dashboard> ); return ( <Dashboard page="events" isUpcoming={true}> {account ? ( <div> {data && data.events.length == 0 && <p>No upcoming events found</p>} {data && data.events.length > 0 && ( <ul role="list" className="grid grid-cols-2 gap-x-4 gap-y-8 sm:grid-cols-3 sm:gap-x-6 lg:grid-cols-4 xl:gap-x-8" > {data.events.map((event) => ( <li key={event.id}> <EventCard id={event.id} name={event.name} eventTimestamp={event.eventTimestamp} imageURL={event.imageURL} /> </li> ))} </ul> )} </div> ) : ( <div className="flex flex-col items-center py-8"> <p className="mb-4">Please connect your wallet to view your events</p> <ConnectButton /> </div> )} </Dashboard> ); }

✋ Need Help?

If you need help, check to see if your question has already been asked in #section-8-help. If you don't see it in there, post a question with any details that would make it easy for a team member to help you. We'll answer most frequently asked questions in live office hours, so keep an eye out in #announcements for those!

End of Day 15


Writers: Sarah Schwartz