1
- import React , { useState } from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
2
import { ListItemIcon } from '../../base' ;
3
3
import { useTheme } from '../../theme' ;
4
4
import CollapsibleSection from './CollapsibleSection' ;
@@ -16,15 +16,35 @@ const TechnologySection: React.FC<TechnologySectionProps> = ({
16
16
technologies
17
17
} ) => {
18
18
const [ openTechnologies , setOpenTechnologies ] = useState ( true ) ;
19
-
19
+ const [ validTechnologies , setValidTechnologies ] = useState < string [ ] > ( [ ] ) ;
20
20
const theme = useTheme ( ) ;
21
21
22
+ useEffect ( ( ) => {
23
+ // Function to check if SVG exists
24
+ const validateTechnologies = async ( ) => {
25
+ const validTechs = await Promise . all (
26
+ technologies . map ( async ( tech ) => {
27
+ const svg_path = `/${ technologySVGPath } /${ tech . toLowerCase ( ) } /${ technologySVGSubpath } /${ tech . toLowerCase ( ) } -color.svg` ;
28
+ try {
29
+ const response = await fetch ( svg_path ) ;
30
+ return response . ok ? tech : null ;
31
+ } catch {
32
+ return null ;
33
+ }
34
+ } )
35
+ ) ;
36
+ setValidTechnologies ( validTechs . filter ( ( tech ) : tech is string => tech !== null ) ) ;
37
+ } ;
38
+
39
+ validateTechnologies ( ) ;
40
+ } , [ technologies , technologySVGPath , technologySVGSubpath ] ) ;
41
+
22
42
const renderTechnologyItem = ( item : string , index : number ) => {
23
43
const svg_path = `${ technologySVGPath } /${ item . toLowerCase ( ) } /${ technologySVGSubpath } /${ item . toLowerCase ( ) } -color.svg` ;
24
44
return (
25
45
< LabelDiv key = { index } >
26
46
< ListItemIcon sx = { { minWidth : '1.5rem' , marginRight : 1 } } >
27
- < img height = "24px" width = "24px" src = { `/${ svg_path } ` } alt = "technology icon" />
47
+ < img height = "24px" width = "24px" src = { `/${ svg_path } ` } alt = { ` ${ item } icon` } />
28
48
</ ListItemIcon >
29
49
{ item }
30
50
</ LabelDiv >
@@ -46,7 +66,7 @@ const TechnologySection: React.FC<TechnologySectionProps> = ({
46
66
title = "TECHNOLOGY"
47
67
isOpen = { openTechnologies }
48
68
onToggle = { ( ) => setOpenTechnologies ( ( prev ) => ! prev ) }
49
- items = { technologies }
69
+ items = { validTechnologies }
50
70
renderItem = { renderTechnologyItem }
51
71
emptyState = { 'No technologies assigned to this design' }
52
72
tooltip = { 'Technologies used in this design' }
0 commit comments