@@ -14,50 +14,30 @@ interface FooterProps {
1414 client : GraphClient ;
1515}
1616
17+ const mapToLinks = ( items : any [ ] | null ) =>
18+ items ?. map ( ( item : any ) => ( {
19+ label : item . _metadata ?. displayName ,
20+ href : item . _metadata ?. url ?. hierarchical ,
21+ } ) ) ?? [ ] ;
22+
1723async function Footer ( { client } : FooterProps ) {
18- const allLinks = await Promise . all ( [
24+ const [ products , company , newsEvents ] = await Promise . all ( [
1925 client . getItems ( '/en/' ) ,
2026 client . getItems ( '/en/about-us' ) ,
2127 client . getItems ( '/en/about-us/news-events' ) ,
2228 ] ) ;
2329
24- // Flatten the array of arrays and map to FooterLink format
25- const footerLinks = allLinks . flat ( ) . map ( ( ancestor : any ) => ( {
26- key : ancestor . _metadata ?. key ,
27- label : ancestor . _metadata ?. displayName ,
28- href : ancestor . _metadata ?. url ?. hierarchical ,
29- } ) ) ;
30-
31- // Group links by category based on URL patterns
32- const categorizedLinks = footerLinks . reduce < {
33- products : FooterLink [ ] ;
34- company : FooterLink [ ] ;
35- news : FooterLink [ ] ;
36- } > (
37- ( acc , link ) => {
38- if ( link . href ?. match ( / \/ a b o u t - u s \/ n e w s - e v e n t s \/ .+ / ) ) {
39- acc . news . push ( { label : link . label , href : link . href } ) ;
40- } else if ( link . href ?. includes ( '/about-us' ) ) {
41- acc . company . push ( { label : link . label , href : link . href } ) ;
42- } else if ( link . href ) {
43- acc . products . push ( { label : link . label , href : link . href } ) ;
44- }
45- return acc ;
46- } ,
47- { products : [ ] , company : [ ] , news : [ ] }
48- ) ;
49-
50- const formattedFooterLink : FooterSection [ ] = [
51- { title : 'PRODUCTS' , links : categorizedLinks . products } ,
52- { title : 'THE COMPANY' , links : categorizedLinks . company } ,
53- { title : 'NEWS & EVENTS' , links : categorizedLinks . news } ,
30+ const sections : FooterSection [ ] = [
31+ { title : 'PRODUCTS' , links : mapToLinks ( products ) } ,
32+ { title : 'THE COMPANY' , links : mapToLinks ( company ) } ,
33+ { title : 'NEWS & EVENTS' , links : mapToLinks ( newsEvents ) } ,
5434 ] ;
5535
5636 return (
5737 < footer className = "bg-gray-800 text-white" >
5838 < div className = "max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12" >
5939 < div className = "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8" >
60- { formattedFooterLink . map ( ( section , index ) => (
40+ { sections . map ( ( section , index ) => (
6141 < div key = { index } className = "space-y-4" >
6242 < h3 className = "text-sm font-bold uppercase tracking-wider text-white" >
6343 { section . title }
0 commit comments