Skip to content

Commit 2b72a6a

Browse files
Merge pull request #26 from WRCRoboticsClub/dev-prashant
added the event.js
2 parents 284408e + 1e7aa6c commit 2b72a6a

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

src/pages/events.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
import { Container, Box, Heading, Text, Image, Button } from "theme-ui";
22
import PreviousEvents from "../components/previousEvents";
3-
//import BannerImg from "../assets/events/b_f_s_2079.jpg";
43
import { useRouter } from "next/router";
54

6-
// TODO : event expansion page
5+
// Add the URL transformation function
6+
function fixDriveUrl(url) {
7+
if (!url) return "";
8+
9+
// Extract file ID from common Google Drive URL patterns
10+
const idMatch = url.match(/(?:id=|\/d\/)([a-zA-Z0-9_-]+)/);
11+
if (!idMatch) return url;
12+
const fileId = idMatch[1];
13+
14+
// Construct lh3.googleusercontent.com direct URL for image thumbnails
15+
return `https://lh3.googleusercontent.com/d/${fileId}=s0`;
16+
}
17+
718
export default function Events({ eventData }) {
8-
// in the event data, if there comes 1 from backend that is the highlighted data, so present it in container
9-
const highlightData = eventData.data.find((e) => e.status[0] == "1");
10-
const previousData = eventData.data.filter((e) => e.status[0] !== "1");
11-
// console.log(previousData);
12-
// console.log(highlightData);
19+
// Fix image URLs in all event data
20+
const fixedEventData = {
21+
...eventData,
22+
data: eventData.data.map(event => ({
23+
...event,
24+
image: event.image.map(fixDriveUrl)
25+
}))
26+
};
27+
28+
const highlightData = fixedEventData.data.find((e) => e.status[0] == "1");
29+
const previousData = fixedEventData.data.filter((e) => e.status[0] !== "1");
30+
1331
const router = useRouter();
1432
const getFullUrl = (url) => {
1533
if (url.startsWith('http://') || url.startsWith('https://')) return url;
@@ -31,6 +49,7 @@ export default function Events({ eventData }) {
3149
) : (
3250
<Box sx={styles.banner.container}>
3351
<Box sx={styles.banner.imageBox}>
52+
{/* Use transformed URL */}
3453
<Image src={highlightData.image[0]} alt="banner" />
3554
</Box>
3655
<Box sx={styles.banner.contentBox}>
@@ -60,19 +79,17 @@ export default function Events({ eventData }) {
6079
</Box>
6180
</Box>
6281
<Box>
82+
{/* Pass fixed data to PreviousEvents */}
6383
<PreviousEvents previousEvents={previousData} />
6484
</Box>
6585
</Box>
6686
);
6787
}
6888

6989
export async function getStaticProps() {
70-
// Fetch data from external API
7190
const res = await fetch("https://wrcrobotics.pythonanywhere.com/events");
72-
7391
const eventData = await res.json();
7492

75-
// Pass data to the page via props
7693
return { props: { eventData } };
7794
}
7895

0 commit comments

Comments
 (0)