Skip to content

Commit 1c010ef

Browse files
committed
feat: show only valid svgs
Signed-off-by: Amit Amrutiya <[email protected]>
1 parent d3090d7 commit 1c010ef

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/custom/CatalogDetail/RightPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ interface RightPanelProps {
1717
showCaveats: boolean;
1818
classes: Class[];
1919
patternsPerUser: PatternsPerUser;
20-
onSuggestedPatternClick: (pattern: Pattern) => void;
2120
handleCopyUrl: (type: string, name: string, id: string) => void;
22-
fontFamily?: string;
21+
onSuggestedPatternClick: (pattern: Pattern) => void;
2322
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2423
useGetUserProfileByIdQuery: any;
24+
fontFamily?: string;
2525
}
2626

2727
const RightPanel: React.FC<RightPanelProps> = ({

src/custom/CatalogDetail/TechnologySection.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { ListItemIcon } from '../../base';
33
import { useTheme } from '../../theme';
44
import CollapsibleSection from './CollapsibleSection';
@@ -16,15 +16,35 @@ const TechnologySection: React.FC<TechnologySectionProps> = ({
1616
technologies
1717
}) => {
1818
const [openTechnologies, setOpenTechnologies] = useState(true);
19-
19+
const [validTechnologies, setValidTechnologies] = useState<string[]>([]);
2020
const theme = useTheme();
2121

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+
2242
const renderTechnologyItem = (item: string, index: number) => {
2343
const svg_path = `${technologySVGPath}/${item.toLowerCase()}/${technologySVGSubpath}/${item.toLowerCase()}-color.svg`;
2444
return (
2545
<LabelDiv key={index}>
2646
<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`} />
2848
</ListItemIcon>
2949
{item}
3050
</LabelDiv>
@@ -46,7 +66,7 @@ const TechnologySection: React.FC<TechnologySectionProps> = ({
4666
title="TECHNOLOGY"
4767
isOpen={openTechnologies}
4868
onToggle={() => setOpenTechnologies((prev) => !prev)}
49-
items={technologies}
69+
items={validTechnologies}
5070
renderItem={renderTechnologyItem}
5171
emptyState={'No technologies assigned to this design'}
5272
tooltip={'Technologies used in this design'}

src/custom/CatalogDetail/UserInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const UserInfo: React.FC<UserInfoProps> = ({ details, showVersion = true, userPr
2121
target="_blank"
2222
rel="noopener noreferrer"
2323
>
24-
<span style={{ fontWeight: 'normal' }}>
24+
<span style={{ fontWeight: 'normal', fontSize: '1.2rem' }}>
2525
{userProfile?.first_name} {userProfile?.last_name}
2626
</span>
2727
</RedirectLink>

0 commit comments

Comments
 (0)