1- import { Container , Box , Heading , Text , Image , Button } from "theme-ui" ;
1+ import { Container , Box } from "theme-ui" ;
22import PreviousEvents from "../components/previousEvents" ;
3- import { useRouter } from "next/router" ;
4-
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 ( / (?: i d = | \/ d \/ ) ( [ a - z A - Z 0 - 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- }
173
184export default function Events ( { eventData } ) {
19- // Fix image URLs in all event data
5+ // Clean and fix image URLs
206 const fixedEventData = {
217 ...eventData ,
228 data : eventData . data . map ( event => ( {
@@ -25,132 +11,28 @@ export default function Events({ eventData }) {
2511 } ) )
2612 } ;
2713
28- const highlightData = fixedEventData . data . find ( ( e ) => e . status [ 0 ] == "1" ) ;
14+ // Only previous events shown
2915 const previousData = fixedEventData . data . filter ( ( e ) => e . status [ 0 ] !== "1" ) ;
30-
31- const router = useRouter ( ) ;
32- const getFullUrl = ( url ) => {
33- if ( url . startsWith ( 'http://' ) || url . startsWith ( 'https://' ) ) return url ;
34- return `http://${ url } ` ;
35- } ;
3616
3717 return (
38- < Box >
39- < Box sx = { styles . banner } id = "events" >
40- < Box sx = { styles . backdrop } >
41- < Box sx = { styles . banner . container } >
42- { ! highlightData ? (
43- < Box sx = { styles . banner . contentBox } >
44- < Heading variant = "heroPrimary" sx = { styles . title } >
45- No any active events
46- </ Heading >
47- < Text variant = "subTitle" > Tune in to not miss the surprise thats coming soon</ Text >
48- </ Box >
49- ) : (
50- < Box sx = { styles . banner . container } >
51- < Box sx = { styles . banner . imageBox } >
52- { /* Use transformed URL */ }
53- < Image src = { highlightData . image [ 0 ] } alt = "banner" />
54- </ Box >
55- < Box sx = { styles . banner . contentBox } >
56- < Heading variant = "heroPrimary" sx = { styles . title } >
57- { highlightData . title [ 0 ] }
58- </ Heading >
59- < Box sx = { styles . banner . descriptions } >
60- < Text variant = "title" > Date : { highlightData . date [ 0 ] } </ Text >
61- < Text variant = "subTitle" >
62- Type : { highlightData . type [ 0 ] }
63- </ Text >
64- < Text variant = "subTitle" > { highlightData . desc [ 0 ] } </ Text >
65- </ Box >
66-
67- < a href = { getFullUrl ( highlightData ?. formLink [ 0 ] ) } >
68- < Button
69- sx = { styles . banner . button }
70- variant = "primary"
71- >
72- Join In
73- </ Button >
74- </ a >
75- </ Box >
76- </ Box >
77- ) }
78- </ Box >
79- </ Box >
80- </ Box >
81- < Box >
82- { /* Pass fixed data to PreviousEvents */ }
83- < PreviousEvents previousEvents = { previousData } />
84- </ Box >
18+ < Box sx = { { pt : [ '100px' , '100px' , '100px' ] } } >
19+ < PreviousEvents previousEvents = { previousData } />
8520 </ Box >
8621 ) ;
8722}
8823
24+ // Util to fix Google Drive URLs
25+ function fixDriveUrl ( url ) {
26+ if ( ! url ) return "" ;
27+ const idMatch = url . match ( / (?: i d = | \/ d \/ ) ( [ a - z A - Z 0 - 9 _ - ] + ) / ) ;
28+ if ( ! idMatch ) return url ;
29+ const fileId = idMatch [ 1 ] ;
30+ return `https://lh3.googleusercontent.com/d/${ fileId } =s0` ;
31+ }
32+
33+ // Fetch data at build time
8934export async function getStaticProps ( ) {
9035 const res = await fetch ( "https://wrcrobotics.pythonanywhere.com/events" ) ;
9136 const eventData = await res . json ( ) ;
92-
9337 return { props : { eventData } } ;
9438}
95-
96- const styles = {
97- banner : {
98- pt : [ "140px" , "145px" , "155px" , "170px" , null , null , "180px" , "215px" ] ,
99- pb : [ 2 , null , 0 , null , 2 , 0 , null , 5 ] ,
100- position : "relative" ,
101- container : {
102- minHeight : "60vh" ,
103- maxHeight : "80vh" ,
104- display : "flex" ,
105- flexDirection : "row" ,
106- justifyContent : "center" ,
107- "@media screen and (max-width: 800px)" : {
108- flexDirection : "column" ,
109- top : "0" ,
110- minHeight : "0vh" ,
111- } ,
112- } ,
113- contentBox : {
114- width : [ "100%" , "90%" , "535px" , null , "57%" , "60%" , "68%" , "60%" ] ,
115- mx : "auto" ,
116- textAlign : "center" ,
117- my : [ "20px" , null , null , null , null , 5 ] ,
118- } ,
119- imageBox : {
120- // justifyContent: "left",
121- display : "flex" ,
122- alignContent : "flex-start" ,
123- objectFit : "cover" ,
124- maxWidth : "60%" ,
125- "@media screen and (max-width: 800px)" : {
126- maxWidth : "100%" ,
127- } ,
128- } ,
129- descriptions : {
130- display : "flex" ,
131- flexDirection : "column" ,
132- justifyContent : "center" ,
133- alignItems : "center" ,
134- textAlign : "center" ,
135- mb : [ 3 , null , null , null , null , 7 ] ,
136- } ,
137- } ,
138- backdrop : {
139- maxWidth : "100%" ,
140- backgroundImage : "linear-gradient(to right,white, white,skyblue)" ,
141- backgroundSize : "cover" ,
142- backgroundPosition : "center" ,
143- backgroundRepeat : "no-repeat" ,
144- } ,
145- title : {
146- fontSize : [ 0 , "20px" , null , "25px" ] ,
147- color : "#000000" ,
148- textAlign : "center" ,
149- letterSpacing : [ "1.5px" , null , "2px" ] ,
150- textTransform : "uppercase" ,
151- fontWeight : "700" ,
152- mb : 2 ,
153- mt : 5 ,
154- lineHeight : 1.5 ,
155- } ,
156- } ;
0 commit comments