Skip to content

Commit e436f9a

Browse files
Api fetching started for event page. (#107)
* Added Navbar component to Layout * Fixed Navbar overlapping * Test Workflow * Fixed Navbar overlapping * added footer to layout. fixed navbar links prefetch * changed title,changed icon * Added Complete Events Page * Added mobile css for events page, added winners sections * fixed winners section font * fixed * Added Blogs Page * Deleted some temporary files * Blogs Page Fixes, Changed Projects to Blogs * Added Contact Us page * Jenil's Changes * Bucket env variable changed for all files. * Api fetching for Event page started, also added delete button for admin
1 parent f52a3ad commit e436f9a

File tree

7 files changed

+153
-60
lines changed

7 files changed

+153
-60
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
import { createClient } from "@/utils/supabase/server";
3+
4+
export async function GET(request: NextRequest): Promise<NextResponse> {
5+
try {
6+
const supabase = createClient();
7+
const {
8+
data: { user },
9+
error: userError,
10+
} = await supabase.auth.getUser();
11+
if (userError || !user) {
12+
return NextResponse.json({ isAdmin: false }, { status: 200 });
13+
}
14+
const isAdmin = await supabase
15+
.from("users")
16+
.select("admin")
17+
.eq("id", user.id);
18+
19+
if (isAdmin) {
20+
return NextResponse.json({ isAdmin: true }, { status: 200 });
21+
} else {
22+
return NextResponse.json({ isAdmin: false }, { status: 200 });
23+
}
24+
} catch (error) {
25+
console.error(error);
26+
return NextResponse.json({ isAdmin: false }, { status: 200 });
27+
}
28+
}

src/app/api/v1/create/event/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
103103

104104
if (poster_file && poster) {
105105
const { error: posterUploadError } = await supabase.storage
106-
.from(process.env.BUCKET || "")
106+
.from(process.env.NEXT_PUBLIC_BUCKET || "")
107107
.upload(`/events/${eventId}/poster`, poster, {
108108
upsert: true,
109109
});

src/app/api/v1/get/blog/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
3131
const blogFileUrl = `${getPublicUrl(`/blogs/${id}/blog`)}`;
3232

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

3737
if (imagesError) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useState, useEffect } from "react";
2+
import axios from "axios";
3+
4+
const checkIsAdmin = () => {
5+
const [isAdmin , setIsAdmin] = useState(false)
6+
useEffect(() => {
7+
const fetchIsAdmin = async () => {
8+
try {
9+
const response = await axios.get(`/api/rest/v1/isUserAdmin`);
10+
const result = response.data;
11+
setIsAdmin(result.isAdmin);
12+
} catch (error) {
13+
console.error(error);
14+
}
15+
};
16+
17+
fetchIsAdmin();
18+
}, [isAdmin]);
19+
20+
return isAdmin;
21+
};
22+
23+
export default checkIsAdmin;

src/app/event/[id]/components/event.jsx

+19-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import EventPoster from "./eventPoster";
55
import EventDetails from "./eventDetails";
66
import useWindowDimensions from "./currentWindowSize";
77

8+
import { getPublicUrl } from "@/lib/utils";
9+
810
function GenerateEvent({ props: event }) {
911
// Getting current window dimensions
1012
const { width, height } = useWindowDimensions();
@@ -18,6 +20,8 @@ function GenerateEvent({ props: event }) {
1820
const [eventPosterFixed, setEventPosterFixed] = useState("");
1921
const [eventPosterCover, setEventPosterCover] = useState("");
2022

23+
const [eventPosterAspectRatio, setEventPosterAspectRatio] = useState(1);
24+
2125
const handleScroll = () => {
2226
const position = window.scrollY;
2327
setScrollPosition(position);
@@ -26,7 +30,7 @@ function GenerateEvent({ props: event }) {
2630
// To change classes
2731
useEffect(() => {
2832
if (width - height > 0) {
29-
if (scrollPosition > width - height - 0.12 * (width - height)) {
33+
if (scrollPosition > (width - height - (0.12 * (width - height)))/eventPosterAspectRatio) {
3034
//
3135
setEventDetailsFixed("");
3236
setEventPosterFixed("event-poster-fixed");
@@ -50,7 +54,20 @@ function GenerateEvent({ props: event }) {
5054
};
5155
}, []);
5256

53-
const eventPoster = "/event_poster.avif";
57+
const [eventPoster,setEventPoster] = useState(getPublicUrl(`/events/${event.id}/poster`));
58+
useEffect(()=>{
59+
const img = new Image();
60+
img.src = eventPoster;
61+
img.onload = () => {
62+
const ratio = img.width / img.height;
63+
setEventPosterAspectRatio(ratio);
64+
};
65+
66+
img.onerror = () => {
67+
console.error('Failed to load image.');
68+
};
69+
},[]);
70+
5471
return (
5572
<div className="event-div">
5673
<div className={`event-poster ${eventPosterFixed}`}>

src/app/event/[id]/components/eventDetails.jsx

+22-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import EventConvenors from "./eventConvenors";
1010
import EventVenue from "./eventVenue";
1111
import EventWinners from "./eventWinners";
1212

13+
import checkIsAdmin from "./checkIsAdmin";
14+
1315
import { Montserrat } from "next/font/google";
1416
const montserratFont = Montserrat({
1517
weight: ["100", "400"],
1618
subsets: ["latin"],
1719
});
1820

1921
function EventDetails(props) {
20-
const [isAdmin, setIsAdmin] = useState(true); //Set default to false
21-
22+
const isAdmin = checkIsAdmin() || false;
2223
const [event, setEvent] = useState(props.event);
2324
const [eventName, setEventName] = useState(event.name);
2425
const [eventDescription, setEventDescription] = useState(event.description);
@@ -36,6 +37,7 @@ function EventDetails(props) {
3637
CalculateDaysLeft(registerUntilDate),
3738
);
3839
const [eventDate, setEventDate] = useState(event.date);
40+
const [eventTime, setEventTime] = useState(event.time);
3941
const [eventDuration, setEventDuration] = useState(
4042
CalculateEventDuration(event.duration),
4143
);
@@ -47,7 +49,8 @@ function EventDetails(props) {
4749
const [eventPrizes, setEventPrizes] = useState(event.prizes);
4850
const [eventConvenors, setEventConvenors] = useState(event.convenors);
4951
const [eventWinners, setEventWinners] = useState(event.winners);
50-
52+
const [eventVenueLink , setEventVenueLink ] = useState(event.venue_link);
53+
5154
//To update the remaining registration time each second
5255
useEffect(() => {
5356
setInterval(() => {
@@ -87,7 +90,7 @@ function EventDetails(props) {
8790
<div className="event-time-container rounded-lg border shadow-sm bg-secondary border-none px-4 py-2 gap-6">
8891
<p className="event-time-title">Event Time</p>
8992
<p className="event-time">
90-
{new Date(eventDate).toLocaleTimeString()}
93+
{convertTo12HourFormat(eventTime)}
9194
</p>
9295
</div>
9396
</div>
@@ -126,15 +129,16 @@ function EventDetails(props) {
126129
>
127130
<EventPrizes eventPrizes={eventPrizes} />
128131
</div>
129-
<div
132+
{eventVenueLink?<div
130133
style={{ width: "100%" }}
131134
className={`lg:col-span-1 lg:row-start-2 lg:row-span-2 order-last ${montserratFont.className}`}
132135
>
133-
<EventVenue />
134-
</div>
136+
<EventVenue venueLink={eventVenueLink}/>
137+
</div>:null}
138+
135139
<div
136-
style={{ width: "100%" }}
137-
className={`lg:col-span-1 lg:row-span-1 ${montserratFont.className}`}
140+
style={{ width: "100%",height:"100%" }}
141+
className={`lg:col-span-1 lg:row-span-1 h-full ${montserratFont.className}`}
138142
>
139143
<EventConvenors eventConvenors={eventConvenors} />
140144
</div>
@@ -166,6 +170,8 @@ function DeleteButton() {
166170

167171
function CalculateDaysLeft(date) {
168172
var today = new Date();
173+
var istOffsetInMilliseconds = 5.5 * 60 * 60 * 1000;
174+
today = new Date(today + istOffsetInMilliseconds);
169175
var anotherDate = new Date(date);
170176
const timeInMS = anotherDate.getTime() - today.getTime();
171177
var daysRemaining = Math.ceil(timeInMS / (1000 * 60 * 60 * 24));
@@ -192,6 +198,13 @@ function CalculateDaysLeft(date) {
192198
}
193199
}
194200

201+
function convertTo12HourFormat(time24) {
202+
let [hours, minutes, seconds] = time24.split(':').map(Number);
203+
let period = hours >= 12 ? 'PM' : 'AM';
204+
hours = hours % 12 || 12;
205+
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${period}`;
206+
}
207+
195208
function CalculateEventDuration(totalmins) {
196209
var absTotal = Math.abs(totalmins);
197210
var mins = absTotal % 60;

src/app/event/[id]/page.jsx

+59-47
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,69 @@ import Loading from "@/components/loading";
77

88
function Event({ params }) {
99
const eventId = params.id;
10-
// const { event, loading, error } = useFetchEvent(eventId);
11-
// const router = useRouter();
10+
const { event, loading, error } = useFetchEvent(eventId);
11+
const router = useRouter();
1212

13-
// if (loading) {
14-
// return <>
15-
// <Loading />
16-
// </>;
17-
// }
13+
if (loading) {
14+
return <>
15+
<Loading />
16+
</>;
17+
}
1818

19-
// if (error) {
20-
// console.error(error);
21-
// router.push('/events');
22-
// return null;
23-
// }
19+
if (error) {
20+
console.error(error);
21+
router.push('/events');
22+
return null;
23+
}
2424

2525
// To start calling api delete the object below and uncomment the above code
26-
const event = {
27-
id: 7,
28-
name: "Codestrike v6.0",
29-
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!`,
30-
date: "2024-08-05T15:30:00",
31-
duration: 60,
32-
mode: false,
33-
host_link: "https://www.hosted.com",
34-
venue: "Mess Hall",
35-
requirements: ["Laptop", "Notebook", "Pen", "Pencil"],
36-
hosted_registration: true,
37-
register_until: "2024-08-05T15:32:30",
38-
registration_link: "https://www.registration.com",
39-
creator: "b4e05b86-df08-49d8-a118-51c205216401",
40-
prizes: [
41-
"Rs. 10000",
42-
"Rs. 5000",
43-
"Rs. 1000",
44-
{
45-
"Female Special": "Rs. 1000",
46-
"FY Special": "Rs. 1000",
47-
},
48-
],
49-
winners: {
50-
"Web Dev": ["ABCDEGFHIJKL", "ABCDEGFHIJKL", "ABCDEGFHIJKL"],
51-
"Cloud ": ["ABCDEGFHIJKL"],
52-
CyberSecurity: ["ABCDEGFHIJKL", "ABCDEGFHIJKL"],
53-
},
54-
convenors: [
55-
"Devyash Saini",
56-
"Devyash Saini",
57-
"Devyash Saini",
58-
"Devyash Saini",
59-
],
60-
};
26+
// const event = {
27+
// "id": 46,
28+
// "name": "CodeStrike v6.0",
29+
// "description": "A competitive coding event",
30+
// "date": "2024-07-30",
31+
// "duration": 180,
32+
// "mode": true,
33+
// "host_link": "https://www.example.com",
34+
// "venue": null,
35+
// "requirements": [
36+
// "Laptop",
37+
// "Notebook"
38+
// ],
39+
// "hosted_registration": true,
40+
// "register_until": "2024-09-28T00:00:00",
41+
// "registration_link": "https://www.example.com",
42+
// "creator": "16ca184e-2872-48e0-b7c1-6425cdc66b0b",
43+
// "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",
44+
// "convenors": [
45+
// "devyash",
46+
// "devyash",
47+
// "devyash"
48+
// ],
49+
// "prizes": [
50+
// "7Cr",
51+
// "69L",
52+
// "3.14L",
53+
// {
54+
// "fy special": "150 Rupiya"
55+
// }
56+
// ],
57+
// "winners": {
58+
// "Web Dev": [
59+
// "ABCDEGFHIJKL",
60+
// "ABCDEGFHIJKL",
61+
// "ABCDEGFHIJKL"
62+
// ],
63+
// "Cloud ": [
64+
// "ABCDEGFHIJKL"
65+
// ],
66+
// "CyberSecurity": [
67+
// "ABCDEGFHIJKL",
68+
// "ABCDEGFHIJKL"
69+
// ]
70+
// },
71+
// "time": "22:29:39"
72+
// };
6173

6274
return <GenerateEvent props={event} />;
6375
}

0 commit comments

Comments
 (0)