Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api fetching started for event page. #107

Merged
merged 34 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f0be92f
Added Navbar component to Layout
deveshsawant05 Jul 26, 2024
02f20d9
Fixed Navbar overlapping
deveshsawant05 Jul 26, 2024
169ad3b
Test Workflow
deveshsawant05 Jul 26, 2024
dcfb8c0
Merge branch 'iiitv:new' into new
deveshsawant05 Jul 26, 2024
20607ff
Fixed Navbar overlapping
deveshsawant05 Jul 26, 2024
c408ef5
Merge branch 'new' of https://github.com/deveshsawant05/iiitvcc into new
deveshsawant05 Jul 26, 2024
28f64b8
Merge branch 'new' of https://github.com/deveshsawant05/iiitvcc into new
deveshsawant05 Jul 27, 2024
ab26882
added footer to layout. fixed navbar links prefetch
deveshsawant05 Jul 29, 2024
ab6071a
Merge branch 'iiitv:new' into new
deveshsawant05 Jul 29, 2024
d460013
changed title,changed icon
deveshsawant05 Jul 29, 2024
054aa62
Merge branch 'new' of https://github.com/deveshsawant05/iiitvcc into new
deveshsawant05 Jul 30, 2024
a085e1f
Merge branch 'iiitv:new' into new
deveshsawant05 Jul 31, 2024
a7baab9
Merge branch 'iiitv:new' into new
deveshsawant05 Jul 31, 2024
fd4d577
Added Complete Events Page
deveshsawant05 Aug 5, 2024
0704d7b
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 5, 2024
c5faf4c
Added mobile css for events page, added winners sections
deveshsawant05 Aug 6, 2024
0072de6
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 6, 2024
aac4b58
fixed winners section font
deveshsawant05 Aug 6, 2024
37e62e6
fixed
deveshsawant05 Aug 6, 2024
1b2ae78
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 7, 2024
8dbda73
Added Blogs Page
deveshsawant05 Aug 10, 2024
db0af49
Deleted some temporary files
deveshsawant05 Aug 10, 2024
c181f5a
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 10, 2024
7fdad10
Blogs Page Fixes, Changed Projects to Blogs
deveshsawant05 Aug 11, 2024
bf06dde
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 12, 2024
f0e06bc
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 12, 2024
7e376c2
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 13, 2024
38cf1e6
Added Contact Us page
deveshsawant05 Aug 14, 2024
2e360b0
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 14, 2024
8781ee6
Jenil's Changes
deveshsawant05 Aug 16, 2024
08015b0
Bucket env variable changed for all files.
deveshsawant05 Aug 17, 2024
dffcf10
Merge branch 'iiitv:new' into new
deveshsawant05 Aug 17, 2024
86d73c0
Api fetching for Event page started, also added delete button for admin
deveshsawant05 Aug 18, 2024
1aa5452
Merge branch 'new' of https://github.com/deveshsawant05/iiitvcc into new
deveshsawant05 Aug 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/app/api/rest/v1/isUserAdmin/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { NextRequest, NextResponse } from "next/server";
import { createClient } from "@/utils/supabase/server";

export async function GET(request: NextRequest): Promise<NextResponse> {
try {
const supabase = createClient();
const {
data: { user },
error: userError,
} = await supabase.auth.getUser();
if (userError || !user) {
return NextResponse.json({ isAdmin: false }, { status: 200 });
}
const isAdmin = await supabase
.from("users")
.select("admin")
.eq("id", user.id);

if (isAdmin) {
return NextResponse.json({ isAdmin: true }, { status: 200 });
} else {
return NextResponse.json({ isAdmin: false }, { status: 200 });
}
} catch (error) {
console.error(error);
return NextResponse.json({ isAdmin: false }, { status: 200 });
}
}
2 changes: 1 addition & 1 deletion src/app/api/v1/create/event/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function POST(request: NextRequest): Promise<NextResponse> {

if (poster_file && poster) {
const { error: posterUploadError } = await supabase.storage
.from(process.env.BUCKET || "")
.from(process.env.NEXT_PUBLIC_BUCKET || "")
.upload(`/events/${eventId}/poster`, poster, {
upsert: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/v1/get/blog/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
const blogFileUrl = `${getPublicUrl(`/blogs/${id}/blog`)}`;

const { data: images, error: imagesError } = await supabase.storage
.from(process.env.BUCKET || "")
.from(process.env.NEXT_PUBLIC_BUCKET || "")
.list(`images/${id}/`);

if (imagesError) {
Expand Down
23 changes: 23 additions & 0 deletions src/app/event/[id]/components/checkIsAdmin.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useState, useEffect } from "react";
import axios from "axios";

const checkIsAdmin = () => {
const [isAdmin , setIsAdmin] = useState(false)
useEffect(() => {
const fetchIsAdmin = async () => {
try {
const response = await axios.get(`/api/rest/v1/isUserAdmin`);
const result = response.data;
setIsAdmin(result.isAdmin);
} catch (error) {
console.error(error);
}
};

fetchIsAdmin();
}, [isAdmin]);

return isAdmin;
};

export default checkIsAdmin;
21 changes: 19 additions & 2 deletions src/app/event/[id]/components/event.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import EventPoster from "./eventPoster";
import EventDetails from "./eventDetails";
import useWindowDimensions from "./currentWindowSize";

import { getPublicUrl } from "@/lib/utils";

function GenerateEvent({ props: event }) {
// Getting current window dimensions
const { width, height } = useWindowDimensions();
Expand All @@ -18,6 +20,8 @@ function GenerateEvent({ props: event }) {
const [eventPosterFixed, setEventPosterFixed] = useState("");
const [eventPosterCover, setEventPosterCover] = useState("");

const [eventPosterAspectRatio, setEventPosterAspectRatio] = useState(1);

const handleScroll = () => {
const position = window.scrollY;
setScrollPosition(position);
Expand All @@ -26,7 +30,7 @@ function GenerateEvent({ props: event }) {
// To change classes
useEffect(() => {
if (width - height > 0) {
if (scrollPosition > width - height - 0.12 * (width - height)) {
if (scrollPosition > (width - height - (0.12 * (width - height)))/eventPosterAspectRatio) {
//
setEventDetailsFixed("");
setEventPosterFixed("event-poster-fixed");
Expand All @@ -50,7 +54,20 @@ function GenerateEvent({ props: event }) {
};
}, []);

const eventPoster = "/event_poster.avif";
const [eventPoster,setEventPoster] = useState(getPublicUrl(`/events/${event.id}/poster`));
useEffect(()=>{
const img = new Image();
img.src = eventPoster;
img.onload = () => {
const ratio = img.width / img.height;
setEventPosterAspectRatio(ratio);
};

img.onerror = () => {
console.error('Failed to load image.');
};
},[]);

return (
<div className="event-div">
<div className={`event-poster ${eventPosterFixed}`}>
Expand Down
31 changes: 22 additions & 9 deletions src/app/event/[id]/components/eventDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import EventConvenors from "./eventConvenors";
import EventVenue from "./eventVenue";
import EventWinners from "./eventWinners";

import checkIsAdmin from "./checkIsAdmin";

import { Montserrat } from "next/font/google";
const montserratFont = Montserrat({
weight: ["100", "400"],
subsets: ["latin"],
});

function EventDetails(props) {
const [isAdmin, setIsAdmin] = useState(true); //Set default to false

const isAdmin = checkIsAdmin() || false;
const [event, setEvent] = useState(props.event);
const [eventName, setEventName] = useState(event.name);
const [eventDescription, setEventDescription] = useState(event.description);
Expand All @@ -36,6 +37,7 @@ function EventDetails(props) {
CalculateDaysLeft(registerUntilDate),
);
const [eventDate, setEventDate] = useState(event.date);
const [eventTime, setEventTime] = useState(event.time);
const [eventDuration, setEventDuration] = useState(
CalculateEventDuration(event.duration),
);
Expand All @@ -47,7 +49,8 @@ function EventDetails(props) {
const [eventPrizes, setEventPrizes] = useState(event.prizes);
const [eventConvenors, setEventConvenors] = useState(event.convenors);
const [eventWinners, setEventWinners] = useState(event.winners);

const [eventVenueLink , setEventVenueLink ] = useState(event.venue_link);

//To update the remaining registration time each second
useEffect(() => {
setInterval(() => {
Expand Down Expand Up @@ -87,7 +90,7 @@ function EventDetails(props) {
<div className="event-time-container rounded-lg border shadow-sm bg-secondary border-none px-4 py-2 gap-6">
<p className="event-time-title">Event Time</p>
<p className="event-time">
{new Date(eventDate).toLocaleTimeString()}
{convertTo12HourFormat(eventTime)}
</p>
</div>
</div>
Expand Down Expand Up @@ -126,15 +129,16 @@ function EventDetails(props) {
>
<EventPrizes eventPrizes={eventPrizes} />
</div>
<div
{eventVenueLink?<div
style={{ width: "100%" }}
className={`lg:col-span-1 lg:row-start-2 lg:row-span-2 order-last ${montserratFont.className}`}
>
<EventVenue />
</div>
<EventVenue venueLink={eventVenueLink}/>
</div>:null}

<div
style={{ width: "100%" }}
className={`lg:col-span-1 lg:row-span-1 ${montserratFont.className}`}
style={{ width: "100%",height:"100%" }}
className={`lg:col-span-1 lg:row-span-1 h-full ${montserratFont.className}`}
>
<EventConvenors eventConvenors={eventConvenors} />
</div>
Expand Down Expand Up @@ -166,6 +170,8 @@ function DeleteButton() {

function CalculateDaysLeft(date) {
var today = new Date();
var istOffsetInMilliseconds = 5.5 * 60 * 60 * 1000;
today = new Date(today + istOffsetInMilliseconds);
var anotherDate = new Date(date);
const timeInMS = anotherDate.getTime() - today.getTime();
var daysRemaining = Math.ceil(timeInMS / (1000 * 60 * 60 * 24));
Expand All @@ -192,6 +198,13 @@ function CalculateDaysLeft(date) {
}
}

function convertTo12HourFormat(time24) {
let [hours, minutes, seconds] = time24.split(':').map(Number);
let period = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12;
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${period}`;
}

function CalculateEventDuration(totalmins) {
var absTotal = Math.abs(totalmins);
var mins = absTotal % 60;
Expand Down
106 changes: 59 additions & 47 deletions src/app/event/[id]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,69 @@ import Loading from "@/components/loading";

function Event({ params }) {
const eventId = params.id;
// const { event, loading, error } = useFetchEvent(eventId);
// const router = useRouter();
const { event, loading, error } = useFetchEvent(eventId);
const router = useRouter();

// if (loading) {
// return <>
// <Loading />
// </>;
// }
if (loading) {
return <>
<Loading />
</>;
}

// if (error) {
// console.error(error);
// router.push('/events');
// return null;
// }
if (error) {
console.error(error);
router.push('/events');
return null;
}

// To start calling api delete the object below and uncomment the above code
const event = {
id: 7,
name: "Codestrike v6.0",
description: `Join us for an exciting coding event organized by Coding Club IIITV, \nwhere teamwork and innovation take center stage! \nIn this unique competition, teams of three programmers will come together to \n solve complex coding challenges within a set timeframe. Participants will need to collaborate closely, leveraging each other's strengths to develop efficient and creative solutions. This event is designed to foster camaraderie, enhance problem-solving skills, and encourage effective communication among team members. Don't miss this opportunity to test your coding prowess, make new friends, and have a blast working together. Sign up now and be part of a thrilling coding adventure!`,
date: "2024-08-05T15:30:00",
duration: 60,
mode: false,
host_link: "https://www.hosted.com",
venue: "Mess Hall",
requirements: ["Laptop", "Notebook", "Pen", "Pencil"],
hosted_registration: true,
register_until: "2024-08-05T15:32:30",
registration_link: "https://www.registration.com",
creator: "b4e05b86-df08-49d8-a118-51c205216401",
prizes: [
"Rs. 10000",
"Rs. 5000",
"Rs. 1000",
{
"Female Special": "Rs. 1000",
"FY Special": "Rs. 1000",
},
],
winners: {
"Web Dev": ["ABCDEGFHIJKL", "ABCDEGFHIJKL", "ABCDEGFHIJKL"],
"Cloud ": ["ABCDEGFHIJKL"],
CyberSecurity: ["ABCDEGFHIJKL", "ABCDEGFHIJKL"],
},
convenors: [
"Devyash Saini",
"Devyash Saini",
"Devyash Saini",
"Devyash Saini",
],
};
// const event = {
// "id": 46,
// "name": "CodeStrike v6.0",
// "description": "A competitive coding event",
// "date": "2024-07-30",
// "duration": 180,
// "mode": true,
// "host_link": "https://www.example.com",
// "venue": null,
// "requirements": [
// "Laptop",
// "Notebook"
// ],
// "hosted_registration": true,
// "register_until": "2024-09-28T00:00:00",
// "registration_link": "https://www.example.com",
// "creator": "16ca184e-2872-48e0-b7c1-6425cdc66b0b",
// "venue_link": "https://maps.google.com/maps?width=100%25&amp;height=600&amp;hl=en&amp;q=Indian%20Institute%20of%20Information%20Technology%20Vadodara+(IIIT%20Vadodara)&amp;t=&amp;z=14&amp;ie=UTF8&amp;iwloc=B&amp;output=embed",
// "convenors": [
// "devyash",
// "devyash",
// "devyash"
// ],
// "prizes": [
// "7Cr",
// "69L",
// "3.14L",
// {
// "fy special": "150 Rupiya"
// }
// ],
// "winners": {
// "Web Dev": [
// "ABCDEGFHIJKL",
// "ABCDEGFHIJKL",
// "ABCDEGFHIJKL"
// ],
// "Cloud ": [
// "ABCDEGFHIJKL"
// ],
// "CyberSecurity": [
// "ABCDEGFHIJKL",
// "ABCDEGFHIJKL"
// ]
// },
// "time": "22:29:39"
// };

return <GenerateEvent props={event} />;
}
Expand Down
Loading