mirror of
https://github.com/0xShay/ticketchain.git
synced 2026-01-11 13:13:25 +00:00
Merge pull request #46 from Ayush272002/bug-usd
Fetch events on homepage and abstract out files
This commit is contained in:
@@ -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<boolean>(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 = () => {
|
||||
<div className="absolute inset-0 bg-black opacity-50 z-10"></div>
|
||||
|
||||
<div className="relative z-20 container mx-auto p-4 pt-16">
|
||||
<Suspense fallback={<p>Loading...</p>}>
|
||||
<Suspense fallback={<div className="mt-4 text-2xl text-white">Loading...</div>}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search events..."
|
||||
@@ -291,7 +269,7 @@ const EventsPage: React.FC = () => {
|
||||
</p>
|
||||
<p className="text-gray-600">{event.location}</p>
|
||||
<p className="text-gray-800 font-semibold">
|
||||
${event.ticketPrice} FLR
|
||||
${event.ticketPrice}
|
||||
</p>
|
||||
<p className="text-gray-600">Host: {event.eventHost}</p>
|
||||
</div>
|
||||
|
||||
70
app/page.tsx
70
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<any>([]);
|
||||
const inputRef = useRef<HTMLInputElement | null>(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 (
|
||||
<>
|
||||
<Header />
|
||||
@@ -102,46 +117,21 @@ export default function Home() {
|
||||
</div>
|
||||
<main>
|
||||
<section className="mb-8 mt-4 mx-auto grid grid-cols-4 col-span-4 gap-4 place-content-center">
|
||||
<FeaturedEvent
|
||||
name="FAB XO Halloween"
|
||||
description="Halloween is upon us and is one of the biggest nights of the FAB XO calendar. Fancy dress is encouraged! So have your fancy dress ready and we look forward to seeing who have the best fancy dress on the night! As a special treat we will be serving our very own witches brew!!!"
|
||||
location="Birmingham, UK"
|
||||
eventStartDate={1729980000}
|
||||
eventHost="0x225C73C8c536C4F5335a2C1abECa95b0f221eeF6"
|
||||
imageURL="https://www.guildofstudents.com/asset/Event/7572/Halloween-Fab-XO-Web-Event.jpg"
|
||||
/>
|
||||
<FeaturedEvent
|
||||
name="Halls Halloween Spooktacular"
|
||||
description="Put on your spookiest costume and head on down to Pritchatts Park and join your Event Activators for our ResLife SPOOKTACULAR on Wednesday 30th October 5-8pm."
|
||||
location="Birmingham, UK"
|
||||
eventStartDate={1730307600}
|
||||
eventHost="0x225C73C8c536C4F5335a2C1abECa95b0f221eeF6"
|
||||
imageURL="https://www.guildofstudents.com/asset/Event/41187/Spooktacular-Web-Event-2024.png"
|
||||
/>
|
||||
<FeaturedEvent
|
||||
name="Halls Halloween Spooktacular"
|
||||
description="Put on your spookiest costume and head on down to Pritchatts Park and join your Event Activators for our ResLife SPOOKTACULAR on Wednesday 30th October 5-8pm."
|
||||
location="Birmingham, UK"
|
||||
eventStartDate={1730307600}
|
||||
eventHost="0x225C73C8c536C4F5335a2C1abECa95b0f221eeF6"
|
||||
imageURL="https://www.guildofstudents.com/asset/Event/41187/Spooktacular-Web-Event-2024.png"
|
||||
/>
|
||||
<FeaturedEvent
|
||||
name="Halls Halloween Spooktacular"
|
||||
description="Put on your spookiest costume and head on down to Pritchatts Park and join your Event Activators for our ResLife SPOOKTACULAR on Wednesday 30th October 5-8pm."
|
||||
location="Birmingham, UK"
|
||||
eventStartDate={1730307600}
|
||||
eventHost="0x225C73C8c536C4F5335a2C1abECa95b0f221eeF6"
|
||||
imageURL="https://www.guildofstudents.com/asset/Event/41187/Spooktacular-Web-Event-2024.png"
|
||||
/>
|
||||
<FeaturedEvent
|
||||
name="Housing Fair"
|
||||
description="We’re hosting a Housing Fair, so make sure you save the date! Whether you’re living in student accommodation or the local community, this will be a great place to start as you begin thinking about where you’ll be living next year."
|
||||
location="Birmingham, UK"
|
||||
eventStartDate={1730804400}
|
||||
eventHost="0x225C73C8c536C4F5335a2C1abECa95b0f221eeF6"
|
||||
imageURL="https://www.guildofstudents.com/asset/Event/41111/Housing-Fair-Web-Event.png"
|
||||
/>
|
||||
{ events.map((ev: any, index: number) => {
|
||||
return <>
|
||||
<a onClick={() => { handleEventClick(ev.eventId) }}>
|
||||
<FeaturedEvent
|
||||
key={ev.eventId}
|
||||
name={ev.name}
|
||||
description={ev.description}
|
||||
location={ev.location}
|
||||
eventStartDate={ev.eventStartDate}
|
||||
eventHost={ev.eventHost}
|
||||
imageURL={ev.images[0] || ""}
|
||||
/>
|
||||
</a>
|
||||
</>
|
||||
}) }
|
||||
</section>
|
||||
</main>
|
||||
<Footer />
|
||||
|
||||
Reference in New Issue
Block a user