11import { Container , Box , Heading , Text , Image , Button } from "theme-ui" ;
22import PreviousEvents from "../components/previousEvents" ;
3- //import BannerImg from "../assets/events/b_f_s_2079.jpg";
43import { 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 ( / (?: 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+ }
17+
718export 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
6989export 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