11import CalendarMonthIcon from '@mui/icons-material/CalendarMonth' ;
2- import { Avatar , styled , useTheme } from '@mui/material' ;
2+ import { Avatar , styled } from '@mui/material' ;
33import React , { useEffect , useState } from 'react' ;
44import { Grid } from '../../base' ;
55import { CloneIcon , CommunityClassIcon , OfficialClassIcon , OpenIcon , ShareIcon } from '../../icons' ;
66import VerificationClassIcon from '../../icons/ContentClassIcons/VerificationClassIcon' ;
77import DeploymentsIcon from '../../icons/Deployments/DeploymentsIcon' ;
88import { DownloadIcon } from '../../icons/Download' ;
9- import { DARK_TEAL } from '../../theme' ;
9+ import { DARK_TEAL , useTheme } from '../../theme' ;
1010import { SNOW_WHITE } from '../../theme/colors/colors' ;
1111import { CustomTooltip } from '../CustomTooltip' ;
12+ import { getVersion , handleImage } from './Helper' ;
1213import {
1314 CardBack ,
1415 CardFront ,
@@ -37,7 +38,10 @@ export const DesignCardUrl = styled('a')(() => ({
3738 textDecoration : 'none'
3839} ) ) ;
3940
40- interface Pattern {
41+ export interface Pattern {
42+ id : string ;
43+ user_id : string ;
44+ pattern_file : string ;
4145 name : string ;
4246 download_count : number ;
4347 clone_count : number ;
@@ -53,8 +57,10 @@ interface Pattern {
5357 } ;
5458 catalog_data ?: {
5559 content_class ?: string ;
56- imageURL ?: string ;
60+ imageURL ?: string [ ] ;
5761 compatibility ?: string [ ] ;
62+ published_version ?: string ;
63+ type ?: string ;
5864 } ;
5965 visibility : string ;
6066 updated_at : Date ;
@@ -63,21 +69,15 @@ interface Pattern {
6369type CatalogCardProps = {
6470 pattern : Pattern ;
6571 patternType : string ;
66- cardLink : string ;
6772 cardHeight : string ;
6873 cardWidth : string ;
6974 cardStyles : React . CSSProperties ;
70- version ?: string ;
7175 avatarUrl : string ;
7276 shouldFlip ?: boolean ;
7377 cardTechnologies ?: boolean ;
7478 isDetailed ?: boolean ;
75- cardAvatarUrl ?: boolean ;
76- date ?: boolean ;
77- cardVersion ?: boolean ;
7879 UserName ?: string ;
7980 children ?: React . ReactNode ; // catalogImage
80- TechnologyComponent ?: React . ReactNode ;
8181 basePath ?: string ; // path of meshmodel img stored
8282 subBasePath ?: string ; // path of meshmodel img stored
8383 getHostUrl ?: ( ) => string ;
@@ -111,7 +111,6 @@ const CustomCatalogCard: React.FC<CatalogCardProps> = ({
111111 shouldFlip,
112112 isDetailed,
113113 cardTechnologies,
114- cardVersion,
115114 avatarUrl,
116115 UserName,
117116 children,
@@ -127,45 +126,13 @@ const CustomCatalogCard: React.FC<CatalogCardProps> = ({
127126 } ;
128127 const theme = useTheme ( ) ;
129128
130- const technologies = pattern . catalog_data ?. compatibility || [ ] ; // an array
129+ const technologies = pattern . catalog_data ?. compatibility || [ ] ;
131130 const techlimit = 5 ;
132131 const [ availableTechnologies , setAvailableTechnologies ] = useState < string [ ] > ( [ ] ) ;
133- const checkImageUrlValidity = async ( url : string , appendHostUrl = true ) => {
134- return new Promise ( ( resolve ) => {
135- const img = new Image ( ) ;
136- // Only append host if the URL does not start with "http" or "https"
137- if ( appendHostUrl && ! url . startsWith ( 'http' ) ) {
138- img . src = ( getHostUrl ? getHostUrl ( ) : '' ) + url ;
139- } else {
140- img . src = url ;
141- }
142- img . onload = ( ) => {
143- // Check if the image loaded successfully
144- resolve ( true ) ;
145- } ;
146-
147- img . onerror = ( ) => {
148- // Handle the case where the image could not be loaded
149- resolve ( false ) ;
150- } ;
151- } ) ;
152- } ;
153-
154- const handleImage = async ( ) => {
155- const validSvgPaths = [ ] ;
156- for ( const technology of technologies ) {
157- const svgIconPath = `${ basePath } /${ technology . toLowerCase ( ) } /${ subBasePath } /${ technology . toLowerCase ( ) } -color.svg` ;
158- const isSvgPathValid = await checkImageUrlValidity ( svgIconPath as string ) ;
159- if ( isSvgPathValid ) {
160- validSvgPaths . push ( technology ) ;
161- }
162- }
163-
164- setAvailableTechnologies ( validSvgPaths ) ;
165- } ;
132+ const version = getVersion ( pattern ) ;
166133
167134 useEffect ( ( ) => {
168- handleImage ( ) ;
135+ handleImage ( technologies , basePath , subBasePath , setAvailableTechnologies ) ;
169136 // eslint-disable-next-line react-hooks/exhaustive-deps
170137 } , [ ] ) ;
171138
@@ -336,9 +303,9 @@ const CustomCatalogCard: React.FC<CatalogCardProps> = ({
336303 </ Grid >
337304 </ DesignDetailsDiv >
338305 ) }
339- { cardVersion && (
306+ { version && (
340307 < VersionDiv >
341- < VersionText > v{ cardVersion } </ VersionText >
308+ < VersionText > v{ version } </ VersionText >
342309 </ VersionDiv >
343310 ) }
344311 </ CardBack >
0 commit comments