diff --git a/app/events/page.tsx b/app/events/page.tsx index ea1643c..429bdc7 100644 --- a/app/events/page.tsx +++ b/app/events/page.tsx @@ -6,6 +6,7 @@ import Header from '../../components/custom/header'; import Footer from '../../components/custom/footer'; import { ethers } from 'ethers'; import { getContract } from '@/lib/ethers'; +import { fetchEvents } from '@/lib/fetchEvents'; export const dynamic = 'force-dynamic'; @@ -40,32 +41,9 @@ const EventsPage: React.FC = () => { const [showFilterMenu, setShowFilterMenu] = useState(false); useEffect(() => { - const fetchEvents = async () => { + const getEvents = async () => { try { - const provider = new ethers.providers.Web3Provider(window.ethereum!); - const contract = getContract().connect(provider); - const eventCount = await contract.eventCounter(); - const eventsData: Event[] = []; - - for (let i = 0; i < eventCount; i++) { - const event = await contract.events(i); - const images = await contract.getEventImages(i); - eventsData.push({ - eventId: i, - name: event.name, - description: event.description, - location: event.location, - capacity: event.capacity.toNumber(), - ticketsSold: event.ticketsSold.toNumber(), - ticketPrice: parseFloat( - ethers.utils.formatEther(event.ticketPrice) - ), - eventStartDate: event.eventStartDate.toNumber(), - eventEndDate: event.eventEndDate.toNumber(), - images: images, - eventHost: event.eventHost, - }); - } + const eventsData: Event[] = (await fetchEvents())!; setEvents(eventsData); setFilteredEvents(eventsData); @@ -87,7 +65,7 @@ const EventsPage: React.FC = () => { } }; - fetchEvents(); + getEvents(); }, [initialQuery]); useEffect(() => { @@ -172,7 +150,7 @@ const EventsPage: React.FC = () => {
- Loading...

}> + Loading...
}> {

{event.location}

- ${event.ticketPrice} FLR + ${event.ticketPrice}

Host: {event.eventHost}

diff --git a/app/page.tsx b/app/page.tsx index 4d3e9ab..282cd8e 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -7,6 +7,7 @@ import { Input } from '@/components/ui/input'; import FeaturedEvent from '@/components/custom/FeaturedEvent'; import { Button } from '@/components/ui/button'; import { FlipWords } from '@/components/ui/flip-words'; +import { fetchEvents } from '@/lib/fetchEvents'; // profile // profile props @@ -15,12 +16,22 @@ import { FlipWords } from '@/components/ui/flip-words'; export default function Home() { const router = useRouter(); const [isClient, setIsClient] = useState(false); + const [events, setEvents] = useState([]); const inputRef = useRef(null); useEffect(() => { setIsClient(true); + fetchEvents().then(eventsData => { + eventsData = eventsData?.sort((a, b) => (a.ticketsSold - b.ticketsSold)); + setEvents(eventsData || []); + }) }, []); + useEffect(() => { + console.log("events updated"); + console.log(events); + }, [events]) + function searchForEvents() { if (inputRef.current?.value === '') { alert('Please enter a search term.'); @@ -54,6 +65,10 @@ export default function Home() { 'gathering', ]; + const handleEventClick = (eventId: number) => { + router.push(`/events/${eventId}`); + }; + return ( <>
@@ -102,46 +117,21 @@ export default function Home() {
- - - - - + { events.map((ev: any, index: number) => { + return <> + { handleEventClick(ev.eventId) }}> + + + + }) }