Skip to content

Commit

Permalink
Jenil's changes (#105)
Browse files Browse the repository at this point in the history
Fixed things
  • Loading branch information
deveshsawant05 authored Aug 16, 2024
1 parent 3fa974a commit f52a3ad
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 1 deletion.
116 changes: 116 additions & 0 deletions src/app/events/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"use client";
import { useEffect, useState } from "react";
import EventBox from "../../components/ui/EventBox";
import { getPublicUrl } from "@/lib/utils"
function Page() {
const [events, setEvents] = useState([]);
const [nextPageEvents, setNextPageEvents] = useState([]);
const [pageCount, setPageCount] = useState(1);
const [hasMoreEvents, setHasMoreEvents] = useState(true);
const [columnCount, setColumnCount] = useState(3);

const fetchEvents = async (page) => {
try {
const response = await fetch(`/api/v1/get/events?page=${page}`);
const data = await response.json();
return data;
} catch (error) {
console.error("Error fetching events:", error);
return [];
}
};

const getMoreEvents = async () => {
setEvents((prevEvents) => [...prevEvents, ...nextPageEvents]);
setPageCount((prev) => prev + 1);

const newEvents = await fetchEvents(pageCount + 2);
if (newEvents.length === 0) {
setHasMoreEvents(false);
} else {
setNextPageEvents(newEvents);
}
};

useEffect(() => {
const loadInitialEvents = async () => {
const firstPageEvents = await fetchEvents(pageCount);
const secondPageEvents = await fetchEvents(pageCount + 1);

setEvents(firstPageEvents);
setNextPageEvents(secondPageEvents);

if (secondPageEvents.length === 0) {
setHasMoreEvents(false);
}
};


const handleResize = () => {
if (window.innerWidth < 768) {
setColumnCount(2);
} else {
setColumnCount(3);
}
};

window.addEventListener("resize", handleResize);
handleResize();
loadInitialEvents();

return () => {
window.removeEventListener("resize", handleResize);
};
}, []);

const columns = Array.from({ length: columnCount }, () => []);

events.forEach((event, index) => {
let posterUrl = getPublicUrl(`/events/${event.id}/poster`)

columns[index % columnCount].push(
<EventBox
img={posterUrl}
key={event.id}
caption={event.description}
time={event.date}
category={event.name}
hostLink={event.host_link}
/>
);
});

return (
<div className="flex flex-col w-full h-full">
<div className="self-center h-fit py-2 w-11/12 flex flex-col bg-[#201f31] mt-4">
<p className="md:pl-12 pt-5 text-2xl font-medium mb-7 ">Events Near</p>
<div className="self-center w-full grid grid-flow-row grid-cols-2 md:grid-cols-3">
{columns.map((column, colIndex) => (
<section
key={colIndex}
className={`h-fit w-full gap-8 py-4 grid grid-flow-row md:pl-12 ${
colIndex === 1 && columnCount === 3 ? "mt-32" : ""
}
${
colIndex === 1 && columnCount === 2 ? "mt-20" : ""
}`
}
>
{column}
</section>
))}
</div>
{hasMoreEvents && (
<button
onClick={getMoreEvents}
className="text-sm md:text-xl hover:border-[#e890bd] text-[#FFBADE] border-[#FFBADE] border-[0.5vh] w-fit px-24 md:px-32 active:scale-95 transition-all duration-100 self-center rounded-3xl py-3"
>
Show More
</button>
)}
</div>
</div>
);
}

export default Page;
34 changes: 34 additions & 0 deletions src/components/ui/EventBox.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";

function EventBox({ time, category, caption, secondCat = false, hostLink , img }) {
return (
<div >
<div style={{
backgroundImage:`url(${img})`,
backgroundPosition:"center",
backgroundRepeat:"no-repeat",
backgroundSize:"cover"
}}
className={`w-11/12 ${
secondCat ? "h-24 md:h-40" : "h-40 md:h-60"
} rounded-3xl ${
secondCat ? "border-[0.1vh]" : "border-[0.4vh] md:border-[1vh]"
} border-[#FFBADE]`}
></div>
<p className="text-[#FFBADE] px-2 md:ml-2 font-mono text-xl md:text-2xl">
{time}
</p>
<p className="text-[#FFBADE] px-2 md:ml-2 font-mono text-nowrap text-xs md:text-xl">
{category}
</p>
<a
href={hostLink}
className="text-white md:ml-2 hover:underline text-center self-center text-xs md:text-2xl px-2 font-semibold"
>
{caption}
</a>
</div>
);
}

export default EventBox;
2 changes: 1 addition & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export function cn(...inputs: ClassValue[]) {
}

export const getPublicUrl = (path: string) => {
return `https://${process.env.PROJECT_ID}.supabase.co/storage/v1/object/public/${process.env.BUCKET}${path}`;
return `https://${process.env.NEXT_PUBLIC_PROJECT_ID}.supabase.co/storage/v1/object/public/${process.env.NEXT_PUBLIC_BUCKET}${path}`;
};

1 comment on commit f52a3ad

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for iiitvcc ready!

✅ Preview
https://iiitvcc-3nl1mrllo-iiitv-coding-clubs-projects.vercel.app

Built with commit f52a3ad.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.