From d229ade9dd9da1ff5d894a8b1236f446c913cf86 Mon Sep 17 00:00:00 2001 From: Wind-Explorer Date: Fri, 2 Aug 2024 08:51:46 +0800 Subject: [PATCH] Events integration in home page --- client/src/pages/HomePage.tsx | 72 ++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/client/src/pages/HomePage.tsx b/client/src/pages/HomePage.tsx index 998ee8a..1bf4b39 100644 --- a/client/src/pages/HomePage.tsx +++ b/client/src/pages/HomePage.tsx @@ -1,11 +1,25 @@ import { useNavigate } from "react-router-dom"; import { ChevronDoubleDownIcon } from "../icons"; -import { Card, ScrollShadow } from "@nextui-org/react"; +import { Button, button, Card, Chip, ScrollShadow } from "@nextui-org/react"; import { useEffect, useState } from "react"; import { retrieveUserInformation } from "../security/users"; +import instance from "../security/http"; +import config from "../config"; export default function HomePage() { + // TODO: Move all interfaces into a single file + interface Event { + id: number; + title: string; + category: string; + location: string; + time: string; + description: string; + evtPicture: string; // Changed to evtPicture + } + const navigate = useNavigate(); const [userInformation, setUserInformation] = useState(); + const [events, setEvents] = useState([]); useEffect(() => { retrieveUserInformation() @@ -13,6 +27,13 @@ export default function HomePage() { setUserInformation(value); }) .catch(); + try { + instance.get(`${config.serverAddress}/events`).then((res) => { + setEvents(res.data); + }); + } catch (error) { + console.error("Failed to fetch events:", error); + } }); return (
@@ -61,23 +82,54 @@ export default function HomePage() {

- Trending events right now + Events happening right now

- {[...Array(8)].map((_, index) => ( + {events.map((event, index) => ( -
-
-

- Sample event {index + 1} -

-

Description of the sample event {index + 1}

+
+ {event.title} +
+

+ {event.title} +

+

+ {event.description} +

+
+ {event.category} + {event.time} +
+
+ ))} +